How to find the roots of a derivative

조회 수: 8 (최근 30일)
Tabbe
Tabbe 2014년 10월 25일
댓글: Tabbe 2014년 10월 25일
Hi!
I'm trying to find the roots of the derivative.
clear all
m = 10; % kg
l = 5; % m
k = 40; % N/m
g = 9.81;
theta = linspace(0,80,200);
V = 0.5*k*(l^2)*(sind(theta).^2)+0.5*m*g*l*cosd(theta);
dtheta = diff(theta);
dV = diff(V);
deriv = dV./dtheta;
newTheta = theta(1:length(theta)-1);
plot(newTheta, deriv)
guess = input('Make a guess: ');
v = fzero(@(newTheta)(deriv), guess)
But I get:
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 308)
elseif ~isfinite(fx) || ~isreal(fx)
Error in StabilitetB (line 15)
v = fzero(@(nyTheta)(derivatan), guess)
Desperation brought me here, what am I doing wrong?! The plot of the derivative comes up perfectly fine. The issue here has to do with fzero and the anonymous function and I don't understand why.

답변 (2개)

Roger Stafford
Roger Stafford 2014년 10월 25일
Rather than tell you what is wrong with your method, I prefer to tell you how I think you should approach the problem. The derivative of V with respect to theta in degrees, using the principles of calculus is:
dV/dtheta = (0.5*k*L^2*2*sind(theta)*cosd(theta) - 0.5*m*g*L*sind(theta))*pi/180
= 0.5*L*pi/180*sind(theta) * (2*k*L*cosd(theta)-m*g)
Expressed in this factored form it is quickly evident that the derivative is zero whenever sind(theta) = 0 or when cosd(theta) = m*g/(2*k*L). Hence its roots are:
theta = 180*n
for any integer n, along with
theta = acosd(m*g/(2*k*L)) or 360-acosd(m*g/(2*k*L))
together with any integral multiple of 360 degrees added or subtracted from these. Using that method is very much more satisfactory than resorting to an iterative approach. (By the way, it's a lot easier to deal with derivatives of the trigonometric functions if you use radians rather than degrees.)
  댓글 수: 3
Roger Stafford
Roger Stafford 2014년 10월 25일
Well, in answer to that, you have defined only a discrete approximation to the derivative of your function by using 'linspace'. This will not work for 'fzero' which expects to be able to assign arbitrary values to the arguments of the functions for which it is finding roots. If you wish to use 'fzero', at the very least you will have to use matlab's symbolic form of 'diff' to find an accurate formula for the derivative function. Having done so, it seems a shame to use 'fzero' when the roots are so obvious at that point.
Tabbe
Tabbe 2014년 10월 25일
Oh yeah, you're absolutely right. If my guess is for instance 70 degrees, there's little chance that there actually is such a number in the array.
I'll have to do it your way meanwhile and hopefully that goes well. Thanks!

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


Zoltán Csáti
Zoltán Csáti 2014년 10월 25일
I recommend to differentiate V(theta) by hand and then use fzero.
  댓글 수: 1
Tabbe
Tabbe 2014년 10월 25일
Thanks for the answer, but I have to derive by using Matlab. :)

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by