plot graph with value when finding fzero

Dear all,
I have question how to let it plot the graph while finding fzero
frad = 220;
rpm = 20000;
m =3;
alpha = 0.1;
R0 = 0.015;
R1 = 0.020;
rpmtoms = rpm*pi*(R0+R1)/(60);
B=pi*(R0+R1)/(m);
L=R1-R0;
ita=0.01; %from prof.
h0 = 0.00002;
k = B*tan(alpha*pi/180)/h0;
% fu = -(6*ita*rpmtoms*L*B^2)*(-log(k+1)+(2*k)/(k+2))/((k^2)*(h0^2));
f = @(h0) (-(6*ita*rpmtoms*L*B^2)*(-log(k+1)+(2*k)/(k+2))/((k^2)*(h0^2))) - frad;
h0 = fzero(f,h0)
I would like to see the graph because it seems like it depends on the initial value i set so i am not sure how much should i set? and my answer would be close to zero like in 1e-6 but cannot set it to zero. i read in some matlab questions i need to set the range for my h0 but in this case since the result close to zero but cannot be zero.
Thank you

10 个评论

What value are you trying to find from fzero()? , it’s a bit confusing.
Dear Madhan Ravi,
I would like to find value of h0 which makes
(-(6*ita*rpmtoms*L*B^2)*(-log(k+1)+(2*k)/(k+2))/((k^2)*(h0^2))) - frad =0
There are two solutions. Your equation is a quadratic of the form
constant/h0^2 - another_constant == 0
which can be solved by multiplying through by h0^2 to get
constant - another_constant*h0^2 == 0
which has solution
h0 = +/- sqrt(constant / another_constant)
Dear Walter Roberson,
Ahhhh so it doesn't correct to use fzero right? because fzero cannot find a root of a function such as x^2.
It just means that you should provide bounds,
fzero(f, [sqrt(realmin), realmax])
to ensure that it does not accidentally try negative values.
Dear Walter Roberson,
I wonder about the value of h0 when it computes k
k = B*tan(alpha*pi/180)/h0;
since i set the initial for h0
h0 = 0.00002;
when it tries to find h0 that makes fzero will it also change the value of h0 when it compute the next k or k now be a constant? but i want k changing the value related to h0
frad = 220;
rpm = 20000;
m =7.5;
alpha = 1;
R0 = 0.015;
R1 = 0.020;
rpmtoms = rpm*2*pi*(R0+R1)/(2*60);
B=2*pi*(R0+R1)/(2*m);
L=R1-R0;
ita=0.01;
h0 = 0.00002;
k = B*tan(alpha*pi/180)/h0;
f = @(h0) (-(6*ita*rpmtoms*L*B^2)*(-log(k+1)+(2*k)/(k+2))/((k^2)*(h0^2)))-frad;
[h0,fval] = fzero(f, [sqrt(realmin), realmax])
and i also substitute k in f
h0 = 0.00002;
% k = B*tan(alpha*pi/180)/h0;
f = @(h0) (-(6*ita*rpmtoms*L*B^2)*(-log((B*tan(alpha*pi/180)/h0)+1)+(2*(B*tan(alpha*pi/180)/h0))/((B*tan(alpha*pi/180)/h0)+2))/(((B*tan(alpha*pi/180)/h0)^2)*(h0^2)))-frad;
but there is an error said
Error using fzero (line 257)
Function values at interval endpoints must be finite and real.
Error in testhfzero (line 16)
[h0,fval] = fzero(f, [sqrt(realmin), realmax])
Use 1E150 as the upper bound.
Dear Walter Roberson,
I do not know how to set the upper bound 1e150 together with the range of h0
[h0,fval] = fzero(f, [sqrt(realmin), realmax])
[h0, fval] = fzero(f, [sqrt(realmin), 1E150])
Dear Walter Roberson,
i used to try this but it does not work but now it works. Thank you very much ^__^

请先登录,再进行评论。

回答(1 个)

You can substitute the equation expression of the operators * / and ^ with the respective dot operators
f = @(h0) (-(6.*ita.*rpmtoms.*L.*B.^2).*(-log(k+1)+(2.*k)./(k+2))./((k.^2).*(h0.^2))) - frad;
and then use semilogx to see a clearer representation of your function. Adjust the arguments of t to your needs.
t=linspace(0,h0*100,1000);
figure()
semilogx(t,f(t))
hold on
yline(0)

类别

帮助中心File Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by