Why is S=t/10 acceptable and S=t/100 giving me an error term?

1 visualización (últimos 30 días)
I am trying to vary the parameter S from 0.17 to 1.00 by increments of 0.01 and solve for r. I can get it to go from 1.7 to 10 in increments of 0.1, when S=t/10, but I cannot get S=t/100 to work. MATLAB tells me that the error is in that line, but does not describe the cause of the error. Any ideas why this is not letting me do it?
function a=poop(r)
for t=17:1:100;
%why does S=t/10 work and S=t/100 not work?
S=t/100;
radius(t)=fsolve(@(r)(acos((4-(2^0.5)*(2+21*r^2)^0.5)/(3*(2^0.5)*r))...
+2*acos((2^0.5)*(2+21*r^2)^0.5 -1)...
+((4-(2^0.5)*(2+21*r^2)^0.5)/(3*(2^0.5)*(S-2*r^2)))...
*(-(4/3)*r^2+4/9*(2^0.5)*(2+21*r^2)^0.5-(10/9))^0.5...
+((2^0.5)*(2+21*r^2)^0.5-1)/(3*(S-2*r^2))...
*(-r^2/6+(2+21*r^2)^0.5/(9*(2^0.5))-5/36)^0.5 - pi),0.3)
a(t,:)=[S radius(t)]
end
end

Respuesta aceptada

Star Strider
Star Strider el 25 de Nov. de 2015
It throws this error with S = t/100;:
Error using trustnleqn (line 28)
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
I will leave it to you to find out the reason your function is throwing an error with that.
Solution: use something other than t/100.
For example, S = t/100 + eps; works:
tv=17:1:100;
for k1 = 1:length(tv);
%why does S=t/10 work and S=t/100 not work?
t = tv(k1);
S=t/100+eps;
radius(k1)=fsolve(@(r)(acos((4-(2^0.5)*(2+21*r^2)^0.5)/(3*(2^0.5)*r))...
+2*acos((2^0.5)*(2+21*r^2)^0.5 -1)...
+((4-(2^0.5)*(2+21*r^2)^0.5)/(3*(2^0.5)*(S-2*r^2)))...
*(-(4/3)*r^2+4/9*(2^0.5)*(2+21*r^2)^0.5-(10/9))^0.5...
+((2^0.5)*(2+21*r^2)^0.5-1)/(3*(S-2*r^2))...
*(-r^2/6+(2+21*r^2)^0.5/(9*(2^0.5))-5/36)^0.5 - pi),0.3);
a(k1,:)=[S radius(k1)];
end
I also started your index at 1 rather than 17, so you don’t have 16 rows of zeros. You can add the value of ‘t’ to your ‘a’ matrix if you want to keep track of it.
  2 comentarios
Matt
Matt el 25 de Nov. de 2015
Thank you much. It turns out my guess was directly on top of an undefined point and anything else was acceptable. Thanks for the other advice, too.
Star Strider
Star Strider el 25 de Nov. de 2015
As always, my pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by