Designing an iterative algorithm for a nonlinear system of equations
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kelly Catlin
el 30 de En. de 2018
Respondida: Alex Sha
el 8 de Feb. de 2020
I am trying to design a function root2d2 (with a nested function root2d) that takes an input t and iterates pre-programmed initial values through fsolve to numerically approximate a system solution. There are three nonlinear equations involved with rather nasty coefficients.
function F = root2d2(t)
t_0 = 21.54851793;
x_0 = [20.7936,20.7936,0.0022222222];
fun = @root2d;
x_0 = fsolve(fun,x_0);
while t_0 <= t
x_0 = fsolve(fun,x_0);
t_0 = t_0 + 0.5;
function F = root2d(x)
F(1) = 0.0022222222*(1 - exp(-x(1)*0.95))^(-1) - x(3);
F(2) = 0.0102597835*(1 - 4*exp(-1.9*t_0 + 1.9*x(2)))^(0.5) - x(3);
F(3) = 4000000 + 10000*x(2) - 0.5540166205/x(3)^2 - 1.052631579*(x(2)-x(1))*x(3)^2 - 213157.8947*(-1.578947368 + x(1) + 2.105263158*exp(-0.95*x(1)) - 0.5263157895*exp(-1.9*x(1)));
end
end
However, when attempting to call the function, I receive an error. This is the error message I received after attempting to call the function:
>> fun = root2d2(25);
Error: File: root2d2.m Line: 11 Column: 5
Function definition is misplaced or improperly nested.
Am I calling the function incorrectly, and/or are there syntax errors in my code?
0 comentarios
Respuesta aceptada
Star Strider
el 30 de En. de 2018
The principal problem is that you are calling the function from within the function.
I cannot figure out what you are doing. This is my best guess to get your code to work:
t = 25;
t_0 = 21.54851793;
x_0 = [20.7936,20.7936,0.0022222222];
k1 = 0;
while t_0 <= t
k1 = k1+1;
x(:,k1) = fsolve(@root2d,x_0);
t_0 = t_0 + 0.5
end
X % Output Result
function F = root2d(x)
F(1) = 0.0022222222*(1 - exp(-x(1)*0.95))^(-1) - x(3);
F(2) = 0.0102597835*(1 - 4*exp(-1.9*t_0 + 1.9*x(2)))^(0.5) - x(3);
F(3) = 4000000 + 10000*x(2) - 0.5540166205/x(3)^2 - 1.052631579*(x(2)-x(1))*x(3)^2 - 213157.8947*(-1.578947368 + x(1) + 2.105263158*exp(-0.95*x(1)) - 0.5263157895*exp(-1.9*x(1)));
end
Make any necessary changes to get it to do what you want.
Más respuestas (1)
Alex Sha
el 8 de Feb. de 2020
There are two set of solutions:
1
x1: 0.256953706774553
x2: -399.382730699003
x3: 0.0102597835062331
Fevl:
9.92301206481638E-12
-6.23310084102435E-12
4.68173766421387E-9
2:
x1: 20.7935613076643
x2: 20.7934490426555
x3: 0.00222222748385822
Fevl:
-5.27799973995199E-9
6.45898215829608E-6
3.15671786665916E-6
0 comentarios
Ver también
Categorías
Más información sobre Simulation, Tuning, and Visualization en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!