Need help with solve function

2 vues (au cours des 30 derniers jours)
Jacked Daniel
Jacked Daniel le 25 Nov 2019
Commenté : Walter Roberson le 26 Nov 2019
I am writing a script to find local extremas of a function and I got stuck right after the second derivative line 'cause right after that I need to store all solutions (critical points) from the equation of the first derivative equals zero and put them back in f(x), I hope you guys could help, here's what I got so far:
disp('This is MaxImin');
syms x;
disp(' please input f');
f = input('f(x)=');
ans = solve(diff(f),x)
  3 commentaires
Jacked Daniel
Jacked Daniel le 26 Nov 2019
Sorry, what do you mean input string
Walter Roberson
Walter Roberson le 26 Nov 2019
Store into some variable name other than ans
Note: you will typically only get all solutions for polynomials, and with degree greater than 4 you cannot count on MATLAB being able to provide the solutions. Solutions to a polynomial of degree greater than 2 are often in the form of root() or rootof() calls instead of explicit solutions; you can double() the result to get the numeric equivalents.
If you use 'returnconditions', true on the solve() call, you are more likely to get all solutions for non-polynomials; it can return generalized solutions for some trig functions. However it can take a bit of experience to know how to interpret and work with those generalized solutions.
It has been proven that there are functions whose roots cannot be found except by testing all possibilities. The calculus approach you are using depends upon the first derivative of the function being continuous.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Formula Manipulation and Simplification dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by