Create “n” non-lineal equations in a loop and solved by Fsolve
Hi, guys…. I’ve been trying to create euqaitons to solve a non-lineal system in a loop. But, the number of functions to be created depends on the user (2<n<24)…. Turbine seal gas leak though labyrinth.
For example, when n=5 the loop should create 5 functions with 5 unknown variables (x1, x2, x3, x4, x5) and then, the system is solved by fsolve.
Here is my script:
All below variables are known:
n=;
pi=;
p0=;
pn=;
Ag=;
k1=;
k2=;
k3=;
k4=;
The equations:
—————————————————-
F(1)= (k1/p0^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((p0/x(i))^k4-1)+2*((p0/x(1))^k4-1)^2))^2-(x(i)/p0)^k2+(x(i)/p0)^k3];%…………. 1st equation
F(n)= [k1/(x(n-1))^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((x(n-1)/pn)^k4-1)+2*((x(n-)/pn)^k4-1)^2))^2-(pn/x(n-1))^k2+(pn/x(n-1))^k3]; %…………. “n” equation
%…………. for remained equations
For i=2:n-1
F(i) = (k1/(x(i))^2)*(x(n)*(1/(pi*Ag))*(pi+2-*((x(i)/x(i+1))^k4-1)+2*((x(i)/x(i+1))^k4-1)^2))^2- (x(i+1)/x(i))^k2+(x(i+1)/x(i))^k3;
End
————–
factor=(p0-pn)/n;
for i=1:(n-1)
x0(i)=p0-factor*i;
end
x0(n)=0;
——————-
options=optimoptions(‘fsolve’,’Display’,’iter’);
[x11,fval]=fsolve(F,x0,options)
Any help will be appreciated guys
Thanks in advance.Hi, guys…. I’ve been trying to create euqaitons to solve a non-lineal system in a loop. But, the number of functions to be created depends on the user (2<n<24)…. Turbine seal gas leak though labyrinth.
For example, when n=5 the loop should create 5 functions with 5 unknown variables (x1, x2, x3, x4, x5) and then, the system is solved by fsolve.
Here is my script:
All below variables are known:
n=;
pi=;
p0=;
pn=;
Ag=;
k1=;
k2=;
k3=;
k4=;
The equations:
—————————————————-
F(1)= (k1/p0^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((p0/x(i))^k4-1)+2*((p0/x(1))^k4-1)^2))^2-(x(i)/p0)^k2+(x(i)/p0)^k3];%…………. 1st equation
F(n)= [k1/(x(n-1))^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((x(n-1)/pn)^k4-1)+2*((x(n-)/pn)^k4-1)^2))^2-(pn/x(n-1))^k2+(pn/x(n-1))^k3]; %…………. “n” equation
%…………. for remained equations
For i=2:n-1
F(i) = (k1/(x(i))^2)*(x(n)*(1/(pi*Ag))*(pi+2-*((x(i)/x(i+1))^k4-1)+2*((x(i)/x(i+1))^k4-1)^2))^2- (x(i+1)/x(i))^k2+(x(i+1)/x(i))^k3;
End
————–
factor=(p0-pn)/n;
for i=1:(n-1)
x0(i)=p0-factor*i;
end
x0(n)=0;
——————-
options=optimoptions(‘fsolve’,’Display’,’iter’);
[x11,fval]=fsolve(F,x0,options)
Any help will be appreciated guys
Thanks in advance. Hi, guys…. I’ve been trying to create euqaitons to solve a non-lineal system in a loop. But, the number of functions to be created depends on the user (2<n<24)…. Turbine seal gas leak though labyrinth.
For example, when n=5 the loop should create 5 functions with 5 unknown variables (x1, x2, x3, x4, x5) and then, the system is solved by fsolve.
Here is my script:
All below variables are known:
n=;
pi=;
p0=;
pn=;
Ag=;
k1=;
k2=;
k3=;
k4=;
The equations:
—————————————————-
F(1)= (k1/p0^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((p0/x(i))^k4-1)+2*((p0/x(1))^k4-1)^2))^2-(x(i)/p0)^k2+(x(i)/p0)^k3];%…………. 1st equation
F(n)= [k1/(x(n-1))^2)*(x(n)*(1/(pi*Ag))*(pi+2-5*((x(n-1)/pn)^k4-1)+2*((x(n-)/pn)^k4-1)^2))^2-(pn/x(n-1))^k2+(pn/x(n-1))^k3]; %…………. “n” equation
%…………. for remained equations
For i=2:n-1
F(i) = (k1/(x(i))^2)*(x(n)*(1/(pi*Ag))*(pi+2-*((x(i)/x(i+1))^k4-1)+2*((x(i)/x(i+1))^k4-1)^2))^2- (x(i+1)/x(i))^k2+(x(i+1)/x(i))^k3;
End
————–
factor=(p0-pn)/n;
for i=1:(n-1)
x0(i)=p0-factor*i;
end
x0(n)=0;
——————-
options=optimoptions(‘fsolve’,’Display’,’iter’);
[x11,fval]=fsolve(F,x0,options)
Any help will be appreciated guys
Thanks in advance. fsolve, loop, nonlinear, functions MATLAB Answers — New Questions