Finding x values for y=0
Mostrar comentarios más antiguos
Hi!
I have a funtion Vprime(theta), as you can see in the graph and defined in the code below.
Im looking for a method to get all the values for theta when Vprime=0. When i use find it only returns "1" but from the graph I know that there are like 20+ values where Vprime=0.

syms theta
V=0.5*k*l^2*sin(theta).^2+0.5*m*g*l*cos(theta) %my function;
Vprime=diff(V,theta) %function differentiated
theta=linspace(0,90,200);
Vprime=750.*cos(theta).*sin(theta) - (1473.*sin(theta))/4;
figure; plot(theta,Vprime)
find(Vprime==0)
Respuestas (1)
dpb
el 19 de Oct. de 2016
"from the graph I know that there are like 20+ values where Vprime=0."
NO! You don't know that at all; what the graph shows is that there are a number of zero-crossings. That doesn't mean there's a value in the computed Vprime that's zero...
>> s=sign(Vprime); % keep the sign only
>> s(s==0)=1; % fixup the zeros (+0)
>> d=[0 diff(s)];
>> ix=find(abs(d)==2); % find the crossings
>> [Vprime(ix-1).' Vprime(ix).'] % show the results...
ans =
74.9148 -204.1960
-436.0735 27.0945
167.6913 -93.1383
-126.2931 18.4546
...
43.9111 -135.3820
-81.2379 81.3830
135.3234 -44.2028
>>
Observe many crossings but no values even very close to zero, what more precisely zero (excepting the origin).
You can use interpolate to find an estimate for what the theta values would between these locations or use fsolve similarly.
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!