Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
fsolve for non linear equation
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Star Strider
am 18 Feb. 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 Kommentare
Star Strider
am 19 Feb. 2020
Save the function on your MATLAB search path as:
Almalki_HW2_P3.m
Then run the fsolve code.
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!