How to use fsolve an implicit equation?
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2020-3-13
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
采纳的回答
Walter Roberson
2020-3-13
function F=JW(lp,qo,delpio,k3,y,z) %<- z is an INPUT
F=lp*(y(2)-qo*delpio/y(1)*exp(z/(k3*y(1)^0.40)))-z;
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!