fsolve doesn't give the expected answer
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I done (with the help of a member in another post) a fsolve script. It works but it doesn't give the expected result, or else the output spikes a lot.
Before I create this post i tried to solve my problem with other discussions and I read that there are more solution for trascendental equation (like mine). But I don't uderstand how to solve my problem.
This is my code, i have 12 equation and 13 unknows. I have to impose one of the unknows (T21) and it varies. After i have to calcolate all other 12 unknows while T21 varies.
T21=zeros(1,36);
j=0;
for t=0:0.1:2.755
j=j+1;
T21(j)=0.333*cos(t)-0.245;
end
sol = zeros(12,numel(T21));
for k = 1:numel(T21)
% the results are saved in a row 1...12
% every value of T21 match a column
if T21<=0
sol(:,k) = fsolve(@(x)funzmia(x,T21(k)), 1:12);
else
sol(:,k) = fsolve(@(x)funzmia2(x,T21(k)), 1:12);
end
end
figure;
plot(1:1:28, sol);
title('sol in funzione di t');
xlabe1=('t');
ylabe1=('sol');
grid on;
function F=funzmia(x,T21)
T11=x(1);
T12=x(2);
T13=x(3);
T14=x(4);
T15=x(5);
T22=x(6);
T23=x(7);
r23=x(8);
T31=x(9);
T32=x(10);
T33=x(11);
r32=x(12);
%T21=0
F(1)=(5^(0.5))*cos(T11)+cos(T12)+4*cos(T13)+cos(T14)+(5^(0.5))*cos(T15)-8;
F(2)=(5^(0.5))*sin(T11)+sin(T12)+4*sin(T13)+sin(T14)+(5^(0.5))*sin(T15);
F(3)=cos(T21)+3*cos(T22)+r23*cos(T23);
F(4)=sin(T21)+3*sin(T22)+r23*sin(T23);
F(5)=cos(T31)+r32*cos(T32)+3*cos(T33);
F(6)=sin(T31)+r32*sin(T32)+3*sin(T33);
F(7)=T12-T21;
F(8)=T31-T14;
F(9)=T13+T22-pi/2;
F(10)=T33-T22-pi;
F(11)=r23-(1+9+6*sin(T12-T13))^(0.5);
F(12)=r32-(1+9+6*cos(T14-T33))^(0.5);
end
function F=funzmia2(x,T21)
T11=x(1);
T12=x(2);
T13=x(3);
T14=x(4);
T15=x(5);
T22=x(6);
T23=x(7);
r23=x(8);
T31=x(9);
T32=x(10);
T33=x(11);
r32=x(12);
%T21=0
F(1)=(5^(0.5))*cos(T11)+cos(T12)+4*cos(T13)+cos(T14)+(5^(0.5))*cos(T15)-8;
F(2)=(5^(0.5))*sin(T11)+sin(T12)+4*sin(T13)+sin(T14)+(5^(0.5))*sin(T15);
F(3)=cos(T21)+3*cos(T22)+r23*cos(T23);
F(4)=sin(T21)+3*sin(T22)+r23*sin(T23);
F(5)=cos(T31)+r32*cos(T32)+3*cos(T33);
F(6)=sin(T31)+r32*sin(T32)+3*sin(T33);
F(7)=T12-T21;
F(8)=T31-T14;
F(9)=T13+T22-3*pi/2;
F(10)=T33-T22-pi;
F(11)=r23-(1+9+6*sin(T12-T13))^(0.5);
F(12)=r32-(1+9+6*cos(T14-T33))^(0.5);
end
0 commentaires
Réponses (4)
Nadir Altinbas
le 13 Nov 2019
error: 'funzmia2' undefined near line 7 column 29
error: __plt2vm__: matrix dimensions must match error: called from __plt__>__plt2vm__ at line 419 column 5 __plt__>__plt2__ at line 250 column 14 __plt__ at line 113 column 17 plot at line 223 column 10
1 commentaire
Nadir Altinbas
le 13 Nov 2019
if T21<=0
funzmia(T21)<=0;
???
3 commentaires
Nadir Altinbas
le 13 Nov 2019
i calculated the data is as following;
funzmiaT21 = [0.088000, 0.086336, 0.081362, 0.073127, 0.061713, 0.047235, 0.029837, 0.0096924, -0.012997, -0.038004
syms var funzmia,funzmiab;
funzmia(T21) = zeros(1,28);
j=0;
for t=0:0.1:2.755
j=j+1;
funzmiaT21(j)=0.333*cos(t)-0.245;
end
sol = zeros(12,numel(T21));
for k = 1:numel(T21)
%the results for x are saved in rows 1...12
% every value of T21 match a column
funzmia(T21)<=0
sol(:,k) = fsolve(@(x)funzmia(x,T21(k)), 1:12);
sol(:,k) = fsolve(@(x)funzmiab(x,T21(k)), 1:12);
end
figure;
plot(1:1:28, sol);
title('sol in funzione di t');
xlabe1=('t');
ylabe1=('sol');
grid on;
function F=funzmia(x,T21)
T11=x(1);
T12=x(2);
T13=x(3);
T14=x(4);
T15=x(5);
T22=x(6);
T23=x(7);
r23=x(8);
T31=x(9);
T32=x(10);
T33=x(11);
r32=x(12);
%T21=0
F(1)=(5^(0.5))*cos(T11)+cos(T12)+4*cos(T13)+cos(T14)+(5^(0.5))*cos(T15)-8;
F(2)=(5^(0.5))*sin(T11)+sin(T12)+4*sin(T13)+sin(T14)+(5^(0.5))*sin(T15);
F(3)=cos(T21)+3*cos(T22)+r23*cos(T23);
F(4)=sin(T21)+3*sin(T22)+r23*sin(T23);
F(5)=cos(T31)+r32*cos(T32)+3*cos(T33);
F(6)=sin(T31)+r32*sin(T32)+3*sin(T33);
F(7)=T12-T21;
F(8)=T31-T14;
F(9)=T13+T22-pi/2;
F(10)=T33-T22-pi;
F(11)=r23-(1+9+6*sin(T12-T13))^(0.5);
F(12)=r32-(1+9+6*cos(T14-T33))^(0.5);
end
function F=funzmiab(x,T21)
T11=x(1);
T12=x(2);
T13=x(3);
T14=x(4);
T15=x(5);
T22=x(6);
T23=x(7);
r23=x(8);
T31=x(9);
T32=x(10);
T33=x(11);
r32=x(12);
%T21=0
F(1)=(5^(0.5))*cos(T11)+cos(T12)+4*cos(T13)+cos(T14)+(5^(0.5))*cos(T15)-8;
F(2)=(5^(0.5))*sin(T11)+sin(T12)+4*sin(T13)+sin(T14)+(5^(0.5))*sin(T15);
F(3)=cos(T21)+3*cos(T22)+r23*cos(T23);
F(4)=sin(T21)+3*sin(T22)+r23*sin(T23);
F(5)=cos(T31)+r32*cos(T32)+3*cos(T33);
F(6)=sin(T31)+r32*sin(T32)+3*sin(T33);
F(7)=T12-T21;
F(8)=T31-T14;
F(9)=T13+T22-3.*pi/2;
F(10)=T33-T22-pi;
F(11)=r23-(1+9+6*sin(T12-T13))^(0.5);
F(12)=r32-(1+9+6*cos(T14-T33))^(0.5);
ans:
double('ans');
end
Voir également
Catégories
En savoir plus sur Historical Contests dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!