Hello,
I'm trying to use the options in fsolve but i didn't understand how i can do...
I know that i have to do fsolve(@(x) myfunz,x0,options) but I don't know what i have to write, option=..?
This is my code:
j=0;
xsol=zeros(13,28);
T21=zeros(1,28);
for t=0:0.1:2.7
j=j+1;
T21(j)=0.333*cos(t)-0.245;
jT21=T21(j);
%jT21=0;
jT22=pi/2;%87°
jr23=3.1623;
jT23=4.391248;%248.5°
jT31=0;%0.226;%13°
jr32=3.1623;
jT32=1.8919369;%106°
jT33=1.5*pi;
jT11=1.106538;%62
jT12=0;
jT13=0;%01.5*pi+1.517
jT14=0;%0.226;
jT15=5.176646;%316°
for k=1:numel(T21)
x0=[jT11,jT12,jT13,jT14,jT15,jT22,jT23,jr23,jT31,jT32,jT33,jr32,jT21];
xsol=fsolve(@(x) funzz(x), [kT11,kT12,kT13,kT14,kT15,kT22,kT23,kr23,kT31,kT32,kT33,kr32,jT21]);
kT11=jxsol(1);
kT12=jxsol(2);
kT13=jxsol(3);
kT14=jxsol(4);
kT15=jxsol(5);
kT22=jxsol(6);
kT23=jxsol(7);
kr23=jxsol(8);
kT31=jxsol(9);
kT32=jxsol(10);
kT33=jxsol(11);
kr32=jxsol(12);
end
end
function F=funzz(x)
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=x(13);
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
But when I run it, it says:
Equation solved, fsolve stalled.
fsolve stopped because the relative size of the current step is less than the
default value of the step size tolerance and the vector of function values
is near zero as measured by the default value of the function tolerance.
<stopping criteria details>
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt
algorithm instead.
> In fsolve (line 310)
In wsadfg (line 30)
I saw that Levenberg-Marquardt is linked to options(is it right?), but i didn't understand how i can do.
Another thing, how can i make xsol a xsol(k)? Because matlab give me error if i put it.
Thank you in advance.

 채택된 답변

Matt J
Matt J 2019년 11월 14일
편집: Matt J 2019년 11월 14일

0 개 추천

I know that i have to do fsolve(@(x) myfunz,x0,options)
I don't think so. The exit message says "Equation solved".
Another thing, how can i make xsol a xsol(k)?
for k=1:numel(T21)
xsol(:,k)=fsolve(@(x) funzz(x), [kT11,kT12,kT13,kT14,kT15,kT22,kT23,kr23,kT31,kT32,kT33,kr32,jT21]);
end

댓글 수: 6

Federico MegaMan
Federico MegaMan 2019년 11월 14일
편집: Federico MegaMan 2019년 11월 14일
Thank you for the answer.
So do you think the code is right? Because the output are all costant...
I did some changes for T21 <0 and T21>0 and add the plot, but the output are all costant...
%jT21=0;
kT22=pi/2;%87°
kr23=3.1623;
kT23=4.391248;%248.5°
kT31=0;
kr32=3.1623;
kT32=1.8919369;%106°
kT33=1.5*pi;
kT11=1.106538;%62
kT12=0;
kT13=0;
kT14=0;
kT15=5.176646;%316°
j=0;
xsol=zeros(13,28);
T21=zeros(1,28);
for t=0:0.1:2.7
j=j+1;
T21(j)=0.333*cos(t)-0.245;
jT21=T21(j);
end
x0=[kT11,kT12,kT13,kT14,kT15,kT22,kT23,kr23,kT31,kT32,kT33,kr32,jT21];
for k=1:numel(T21)
if T21<=0
xsol(:,k)=fsolve(@(x) funz1(x), [kT11,kT12,kT13,kT14,kT15,kT22,kT23,kr23,kT31,kT32,kT33,kr32,T21(k)]);
else
xsol(:,k)=fsolve(@(x) funz2(x), [kT11,kT12,kT13,kT14,kT15,kT22,kT23,kr23,kT31,kT32,kT33,kr32,T21(k)]);
end
jxsol=xsol(:,k);
kT11=jxsol(1);
kT12=jxsol(2);
kT13=jxsol(3);
kT14=jxsol(4);
kT15=jxsol(5);
kT22=jxsol(6);
kT23=jxsol(7);
kr23=jxsol(8);
kT31=jxsol(9);
kT32=jxsol(10);
kT33=jxsol(11);
kr32=jxsol(12);
end
figure;
plot(1:1:28, xsol);
title('xsol in funzione di t');
xlabe1=('t');
ylabe1=('xsol');
grid on;
function F=funz1(x)
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=x(13);
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=funz2(x)
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=x(13);
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
So can i ignorate this "Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt
algorithm instead. "?
Matt J
Matt J 2019년 11월 14일
편집: Matt J 2019년 11월 14일
So do you think the code is right? Because the output are all costant...
Of course it is constant. funz1 and T21 aren't changing, so you are solving the same equations over and over again.
So can i ignorate this "Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt
Yes.
Federico MegaMan
Federico MegaMan 2019년 11월 14일
Oh, wait I want they changes. Doesn't T21 vary with for? Anyway how can i let them change?
Matt J
Matt J 2019년 11월 14일
편집: Matt J 2019년 11월 14일
By doing something in the loop that makes them changes with k...? Currently, nothing is done with them.
Federico MegaMan
Federico MegaMan 2019년 11월 14일
I did it putting jxsol=xsol(:,k), and after T11=jxsol(1), T12=jxsol(2), ecc... I did it to changes their value every iteration.
Perhaps you meant to write
if T21(k)<=0 %add indexing

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

질문:

2019년 11월 14일

댓글:

2019년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by