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)
Faisal Al-malki
Faisal Al-malki el 18 de Feb. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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

Respuestas (1)

Star Strider
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
Faisal Al-malki
Faisal Al-malki el 19 de Feb. de 2020
or could you send me the matlab file of this code on my email (fanwsa@gmail.com)
Star Strider
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.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by