How to use fsolve an implicit equation?
Mostrar comentarios más antiguos
clc, clear
a1=28*7*400; %%ft^2
po=40.6; %%psi
delpio=9; %%psi
qf=1525; %%gpm
qo=qf;
pp=16.4; %%psi
qp=1234; %%gpm
depr1=24.9; %%psi
delpr2=18.2; %%psi
PH=360; %%ft
lp=2.76*.264/(60)^2*14.5; %%gal/m*min^2/psi
k2=1.75*10^-4*60^1.67*14.5/264.172^1.67; %%psi/(gal/min)^1.67
k3=2.27*10^-2; %%(m^3/h)^.6/m^2
g=32.17; %%ft/s^2
rhoh20=62.4; %%lbs/ft^3
pf=rhoh20*g*PH*1.488*.000145; %%psi
delpo=pf-po; %%psi
icQ=qo; %%gpm
icdelp=delpo; %%psi
function dydx=odes(jw,a1,k2)
dydx=zeros(2,1);
dydx(1)=-jw*a1;
dydx(2)= -k2*y(1)^1.67;
end
function F=JW(lp,qo,delpio,k3,y)
F=lp*(y(2)-qo*delpio/y(1)*exp(z/(k3*y(1)^0.40))-z;
end
xo=0;
X=@JW
jw=fsolve(JW,xo);
xspan=[0 50];
[x,y]=ode45(@odes,xspan,[icQ icdelp]);
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Error in mhlro (line 24)
jw=fsolve(@(z)JW(lp,qo,delpio,k3,y),xo);
Caused by:
Failure in initial objective function evaluation.
FSOLVE cannot continue.
FIrst is my function of differntial equations
followed by my function that i want to fsolve.
I want to find the number z in the equation but that equation is dependent on the differential equations and the differentials are depenedent on z.
The error i get is below.
8 comentarios
Walter Roberson
el 12 de Mzo. de 2020
@(z)JW(lp,qo,delpio,k3,y)
That ignores z, so fsolve would not be able to propose different input vectors as solutions.
Your code does not match the error message, which makes it confusing.
jw=fsolve(JW,xo);
That would try to invoke JW with no inputs, expecting that it would return a function handle that could be solved against.
Rodrigo Blas
el 12 de Mzo. de 2020
Editada: Walter Roberson
el 12 de Mzo. de 2020
Walter Roberson
el 12 de Mzo. de 2020
F=lp*(y(2)-qo*delpio/y(1)*exp(z/(k3*y(1)^0.40))-z;
1 2 1 2 1 2 3 4 3 21
Should be 0 by the end of the expression.
Rodrigo Blas
el 12 de Mzo. de 2020
Walter Roberson
el 12 de Mzo. de 2020
As I wrote before:
jw=fsolve(JW,xo);
That would try to invoke JW with no inputs, expecting that it would return a function handle that could be solved against.
Remember that MATLAB evaluates all functions and expressions before passing them in to a function. With JW being a function, you are asking to invoke JW and to use whatever JW returns as the first parameter of fsolve() . The first parameter that reaches fsolve() must be a function handle: the first parameter in your call to fsolve() must be something that evaluates to a function handle. Including possibly an expression that builds a handle to an anonymous function.
Rodrigo Blas
el 12 de Mzo. de 2020
Walter Roberson
el 13 de Mzo. de 2020
Yes, that would be a function handle, and is closer to what you need. However your JW function is defined to take 5 inputs, but fsolve() is only going to pass one input to the function handle, so your JW function is not receiving enough inputs.
Reminder of what I posted earlier:
@(z)JW(lp,qo,delpio,k3,y)
That ignores z, so fsolve would not be able to propose different input vectors as solutions
Rodrigo Blas
el 13 de Mzo. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Surrogate Optimization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!