Huge value of angle

2 visualizzazioni (ultimi 30 giorni)
Pavel
Pavel il 4 Mag 2014
Modificato: Star Strider il 4 Mag 2014
After running a code, I get for a and b, which in my case represent angle values huge values. When i ask Matlab to compute sin(a) and/or sin(b), i get a numerical value insted of an error as the one i get on my scientific computer. What is going on? What am I missing out? Thanks a lot.
The code is:
if true
clear
clc
P=2000;
L=1300;
sa=150;
syms a b positive
%se definesc lungimiile elementelor
l1=L/sin(45*pi/180);
l2=L/cos(a*pi/180);
l3=L/cos((a+b)*pi/180);
%eforturile din bare(la ridicarea nedeterminari)
N3(a,b)=(P*cos(a*pi/180))/(cos(a*pi/180)*sin((a+b)*pi/180)-(cos((a+b)*pi/180)*sin(a*pi/180)));
N2(a,b)=((-N3*cos((a+b)*pi/180)))/(cos(a*pi/180));
n3(a,b)=(-sin((a+45)*pi/180))/sin(b*pi/180);
n2(a,b)=(cos(45*pi/180)-n3*cos((a+b)*pi/180))/cos(a*pi/180);
%coeficientii ecuatiei canonice
D1F(a,b)=l2*n2*N2+l3*n3*N3;
d11(a,b)=l1+l2*n2*n2+l3*n3*n3;
%calcularea eforturilor nodale;
X1(a,b)=-D1F/d11;
X3(a,b)=(P*cos(a*pi/180)-X1*sin((45+a)*pi/180))/sin(b*pi/180);
X2(a,b)=(X1*cos(45*pi/180)-X3*cos((a+b)*pi/180))/cos(a);
%functia obiectiv;
V(a,b)=(X1/sa)*l1+(X2/sa)*l2+(X3/sa)*l3;
%derivarea functiei obiectiv
diff_f1=diff(V,a);
diff_f2=diff(V,b);
%Calcularea valorilor numerice
[a, b]=solve(diff_f1, diff_f2)
%conditiilor de maxim global;
conditie1=diff(V,'a',2);
conditie2=diff(V, 'b', 2);
conditie3_1=diff(V, 'a', 'b');
conditie3=conditie1*conditie2-conditie3_1;
%verificarea conditiilor de maxim global
c1=double(conditie1(a,b))
c2=double(conditie2(a,b))
c3=double(conditie3(a,b))
if c1>0, c2>0, c3>0;
disp('Cele 3 condititii sunt verificate, astfel solutiile obtinute reprezinta punctul de maxim global')
end
%calcularea eforturilor nodale
F1=double(X1(a,b))
F2=double(X2(a,b))
F3=double(X3(a,b))
%Se verifica daca valorile obtinute pentru eforturile nodale verifica
%ecuatia de echilibru a fortelor pe directia Y
ver_ec=double(F1*sin(45*pi/180)+F2*sin(a*pi/180)+F3*sin((a+b)*pi/180))
end

Risposta accettata

Star Strider
Star Strider il 4 Mag 2014
Trust the MATLAB answer:
y1 = sin(1E+10 * pi/3)
y2 = sin(-pi/3)
produce:
y1 =
-866.0250e-003
y2 =
-866.0254e-003
  2 Commenti
Pavel
Pavel il 4 Mag 2014
Ok. i will trust Matlab but how do i tell him to display the real angle value(in your exemple pi/3). Thanks
Star Strider
Star Strider il 4 Mag 2014
Modificato: Star Strider il 4 Mag 2014
My pleasure!
It took a bit of experimenting, but if you want the angle printed as a rational fraction of pi, this works:
fprintf(1,'\n\tAngle = %spi\n', rats(a/pi, 4))
See the documentaton on fprintf for details.
For a = pi/3, this produces:
Angle = 1/3 pi
and for a = 2*pi it produces:
Angle = 2 pi
That’s the best I can do!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by