How to find the roots of a derivative

10 Ansichten (letzte 30 Tage)
Tabbe
Tabbe am 25 Okt. 2014
Kommentiert: Tabbe am 25 Okt. 2014
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.

Antworten (2)

Roger Stafford
Roger Stafford am 25 Okt. 2014
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 Kommentare
Roger Stafford
Roger Stafford am 25 Okt. 2014
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 am 25 Okt. 2014
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!

Melden Sie sich an, um zu kommentieren.


Zoltán Csáti
Zoltán Csáti am 25 Okt. 2014
I recommend to differentiate V(theta) by hand and then use fzero.
  1 Kommentar
Tabbe
Tabbe am 25 Okt. 2014
Thanks for the answer, but I have to derive by using Matlab. :)

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by