MATLAB Answers

How to use fsolve with a variable parameter?

50 views (last 30 days)
Hello,
I have a problem with 13 unknows and 12 equations. I already solve the problem imposing T21=0.
I would to variate 1 of the unknows (I prefer T21) to generate various solution.
How can i do?
I attach you my function.
Thank you in advance.

  0 Comments

Sign in to comment.

Accepted Answer

Stephan
Stephan on 10 Nov 2019
Define the values fot T21 that you want to calculate for. Then use a for loop and call your function inside the loop as often as you need. To do so define T21 as an input argument to your function. Don't miss to store the results of every run of your loop in another row or column of your corresponding run of the loop.

  7 Comments

Show 4 older comments
Federico MegaMan
Federico MegaMan on 10 Nov 2019
Oh i'm very sorry i'm new and i didn't know that. I'll keep it in mind for the next times, thank you.
Anyway this is my function:
(the file name is funzmia)
function F=funz(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
and this is the for:
for T21=0:pi/180:5*pi/180
fsolve(@funzmia, [1 2 3 4 5 6 7 8 9 10 11 12])
end
Stephan
Stephan on 11 Nov 2019
T21=0:pi/180:5*pi/180;
sol = zeros(12,numel(T21));
for k = 1:numel(T21)
% Results for x are saved in rows 1...12
% every value of T21 corresponds to 1 column
sol(:,k) = fsolve(@(x)funzmia(x,T21(k)), 1:12);
end
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
Federico MegaMan
Federico MegaMan on 11 Nov 2019
Okay, it works perfectly now. Thank you very much!

Sign in to comment.

More Answers (0)


Translated by