Nonlinear system of equations
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Amanda Hoxell
el 27 de Mayo de 2020
I am trying to solve a system of nonlinear equations. I am not sure what method is the best to use for my problem but using syms does not seem to work. How do I get a numerical solution to the following system of equations?
clear
b1=1000;
b2=100;
c=50;
t=0.76;
T=950;
n=5;
syms sum R1 R2 R3 R4 R5
eq1=(R1-R2)-((1+t)*T*(R2^t-R1^t)+50)/b2 ==0;
eq2=(R2-R3)-((1+t)*T*(R3^t-R2^t)+50)/b2 ==0;
eq3=(R3-R4)-((1+t)*T*(R4^t-R3^t)+50)/b2 ==0;
eq4=(R4-R5)-((1+t)*T*(R5^t-R4^t)+50)/b2 ==0;
eq5=sum-(n*R5+(R4-R5)+2*(R3-R4)+3*(R2-R3)+4*(R1-R2)) ==0;
eq6=R1-(b1-b2*sum-(1+t)*T*R1^t-c)/b2 ==0;
eq7=R2-(b1-b2*sum-(1+t)*T*R2^t-2*c)/b2 ==0;
eq8=R3-(b1-b2*sum-(1+t)*T*R3^t-3*c)/b2 ==0;
eq9=R4-(b1-b2*sum-(1+t)*T*R4^t-4*c)/b2 ==0;
eq10=R5-(b1-b2*sum-(1+t)*T*R5^t-5*c)/b2 ==0;
sol=solve(eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10);
sol;
0 comentarios
Respuesta aceptada
Stephan
el 27 de Mayo de 2020
Editada: Stephan
el 27 de Mayo de 2020
function myEq
b1=1000;
b2=100;
c=50;
t=0.76;
T=950;
n=5;
x0 = [1 1 1 1 1 1];
opts = optimoptions('fsolve', 'Algorithm', 'levenberg-marquardt');
sol = fsolve(@fun, x0, opts)
test = fun(sol)
function eq = fun(x)
Sum = x(1);
R1 = x(2);
R2 = x(3);
R3 = x(4);
R4 = x(5);
R5 = x(6);
eq(1)=(R1-R2)-((1+t)*T*(R2^t-R1^t)+50)/b2;
eq(2)=(R2-R3)-((1+t)*T*(R3^t-R2^t)+50)/b2;
eq(3)=(R3-R4)-((1+t)*T*(R4^t-R3^t)+50)/b2;
eq(4)=(R4-R5)-((1+t)*T*(R5^t-R4^t)+50)/b2;
eq(5)=Sum-(n*R5+(R4-R5)+2*(R3-R4)+3*(R2-R3)+4*(R1-R2));
eq(6)=R1-(b1-b2*Sum-(1+t)*T*R1^t-c)/b2;
eq(7)=R2-(b1-b2*Sum-(1+t)*T*R2^t-2*c)/b2;
eq(8)=R3-(b1-b2*Sum-(1+t)*T*R3^t-3*c)/b2;
eq(9)=R4-(b1-b2*Sum-(1+t)*T*R4^t-4*c)/b2;
eq(10)=R5-(b1-b2*Sum-(1+t)*T*R5^t-5*c)/b2;
end
end
gives acceptabe results:
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
sol =
1.5076 0.3566 0.3279 0.2998 0.2722 0.2453
test =
1.0e-09 *
Columns 1 through 9
-0.0108 -0.0043 0.0059 0.1264 -0.0998 -0.0157 -0.0049 -0.0006 -0.0065
Column 10
-0.1329
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Equation Solving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!