How to solve non-linear equations with integrations?
Show older comments
I want to solve a group of equations like this:
f1 = int(pl*x,x,-L,0)+int(pr*x,x,0,L)+M/d;
f2 = int(pl,x,-L,0)*sin(alph+tilt)+int(pr,x,0,L)*sin(alph-tilt)-G/d-2*L*P_e*sin(alph)*cos(tilt);
f3 = int(pl,x,-L,0)*cos(alph+tilt)-int(pr,x,0,L)*cos(alph-tilt)+2*L*P_e*sin(alph)*sin(tilt);
in which the pl and pr are:
pl = -12*mu_L*rho_S*(int((Uxl*x/(deltal^3)),x,0,x)+Cl*int((1/(deltal^3)),x,0,x))/rho_L+P0;
pr = -12*mu_L*rho_S*(int((Uxr*x/(deltar^3)),x,0,x)+Cr*int((1/(deltar^3)),x,0,x))/rho_L+P0;
The solving prt of code like:
initial_guess = [0.5, 0.1, 2];
solve_equations = @(vars) double(subs([f1, f2, f3], {x1,y1,Uratio}, vars));
result = fsolve(solve_equations, initial_guess);
x1 = result(1);
y1 = result(2);
Uratio = result(3);
But the calculating process time was extremly long and couldn't get the solution, I thought the reason is: there are lots of integrations in the equations and the fsolve function cannot solve the int() part. Is this correct? How to solve it?
8 Comments
Yuting
on 31 Jul 2023
Yuting
on 31 Jul 2023
Torsten
on 31 Jul 2023
Do some of your "parameters" Uxl, Uxr, Cl, Cr, deltal, deltar, P0, mu_L, rho_S, alph, tilt, P_e ... also depend on x ?
Yuting
on 31 Jul 2023
Then follow @Star Strider to work with "matlabFunction", but compute pl and pr first since the result will also depend on x. This will influence int(pl*x,x,-L,0) etc. in the computation of f1, f2 and f3.
syms x L M d alph tilt G P_e delta rho_L Uxl Uxr rho_S mu_L P0 Cr Cl deltal deltar
pl = -12*mu_L*rho_S*(int((Uxl*x/(deltal^3)),x,0,x)+Cl*int((1/(deltal^3)),x,0,x))/rho_L+P0;
pr = -12*mu_L*rho_S*(int((Uxr*x/(deltar^3)),x,0,x)+Cr*int((1/(deltar^3)),x,0,x))/rho_L+P0;
f1 = int(pl*x,x,-L,0)+int(pr*x,x,0,L)+M/d
f2 = int(pl,x,-L,0)*sin(alph+tilt)+int(pr,x,0,L)*sin(alph-tilt)-G/d-2*L*P_e*sin(alph)*cos(tilt)
f3 = int(pl,x,-L,0)*cos(alph+tilt)-int(pr,x,0,L)*cos(alph-tilt)+2*L*P_e*sin(alph)*sin(tilt)
equations = matlabFunction(f1,f2,f3)
Yuting
on 31 Jul 2023
Answers (1)
It is not possible to solve this numerically without substituting numerical values for the known variables.
That aside, use the matlabFunction function to create an anonymous function that fsolve can work with —
syms pl x pr L M d alph tilt G P_e delta rho_L Uxl Uxr rho_S mu_L P0 Cr Cl deltal deltar
f1 = int(pl*x,x,-L,0)+int(pr*x,x,0,L)+M/d
f2 = int(pl,x,-L,0)*sin(alph+tilt)+int(pr,x,0,L)*sin(alph-tilt)-G/d-2*L*P_e*sin(alph)*cos(tilt)
f3 = int(pl,x,-L,0)*cos(alph+tilt)-int(pr,x,0,L)*cos(alph-tilt)+2*L*P_e*sin(alph)*sin(tilt)
pls = -12*mu_L*rho_S*(int((Uxl*x/(deltal^3)),x,0,x)+Cl*int((1/(deltal^3)),x,0,x))/rho_L+P0;
prs = -12*mu_L*rho_S*(int((Uxr*x/(deltar^3)),x,0,x)+Cr*int((1/(deltar^3)),x,0,x))/rho_L+P0;
f1 = simplify(subs(f1, {pl,pr},{pls,prs}), 500)
f2 = simplify(subs(f1, {pl,pr},{pls,prs}), 500)
f3 = simplify(subs(f1, {pl,pr},{pls,prs}), 500)
equations = matlabFunction(f1,f2,f3)
I leave the rest to you.
.
3 Comments
Yuting
on 31 Jul 2023
Yuting
on 31 Jul 2023
Star Strider
on 31 Jul 2023
My pleasure!
The ‘500’ tells simplify too keep simplifying until it cannot simplify the expressins further, or reaches the limit of 500 iterations. Usually 500 is enough, however if not specifically stated, simplify stops after one iteration. For complicated expressions, that is rarely enough.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



