Need help with solve function

조회 수: 2 (최근 30일)
Jacked Daniel
Jacked Daniel 2019년 11월 25일
댓글: Walter Roberson 2019년 11월 26일
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
Jacked Daniel
Jacked Daniel 2019년 11월 26일
Sorry, what do you mean input string
Walter Roberson
Walter Roberson 2019년 11월 26일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by