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

1 Ansicht (letzte 30 Tage)
Matt
Matt am 24 Nov. 2015
Kommentiert: Star Strider am 25 Nov. 2015
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

Akzeptierte Antwort

Star Strider
Star Strider am 25 Nov. 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 Kommentare
Matt
Matt am 25 Nov. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by