Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
fsolve for non linear equation
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
function F=Almalki_HW2_P3(x)
global v V k1 k2 CAin CBin CCin CDin
v=1; V=100; k1=1; k2=1; CAin=1; CBin=2; CCin=0; CDin=0;
F=[v*(CAin-x(1))+V*(-k1*x(1)*x(2));
v*(CBin-x(2))+V*(-k1*x(1)*x(2)-k2*x(1)*x(2));
v*(CCin-x(3))+V*(k1*x(1)*x(2)-k2*x(3)*x(2));
v*(CDin-x(4))+V*(k2*x(3)*x(2))];
x0=[ 0; 0; 0; 0];
options=optimoptions('fsolve','Display','iter');
[x,fval]=fsolve(@Almalki_HW2_P3,x0,options)
end
I typed those code for non linear equations, but when I run the codes, I got this message "Not enough input arguments."
So, do you have any idea
thanks
0 comentarios
Respuestas (1)
Star Strider
el 18 de Feb. de 2020
One problem is that you called fsolve inside the function. That is not appropriate. The other is that you use global variables.
Try this instead:
function F=Almalki_HW2_P3(x, v, V, k1, k2, CAin, CBin, CCin, CDin)
v=1; V=100; k1=1; k2=1; CAin=1; CBin=2; CCin=0; CDin=0;
F=[v*(CAin-x(1))+V*(-k1*x(1)*x(2));
v*(CBin-x(2))+V*(-k1*x(1)*x(2)-k2*x(1)*x(2));
v*(CCin-x(3))+V*(k1*x(1)*x(2)-k2*x(3)*x(2));
v*(CDin-x(4))+V*(k2*x(3)*x(2))];
end
x0=[ 0; 0; 0; 0]+eps;
options=optimoptions('fsolve','Display','iter');
[x,fval]=fsolve(@(x)Almalki_HW2_P3(x, v, V, k1, k2, CAin, CBin, CCin, CDin),x0,options)
I assume here that the other arguments exist in your workspace. I created random scalars for them to test this code. It runs without error.
5 comentarios
Star Strider
el 19 de Feb. de 2020
Save the function on your MATLAB search path as:
Almalki_HW2_P3.m
Then run the fsolve code.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!