I cant find my value for an fsolve.

1 view (last 30 days)
Rodrigo Blas
Rodrigo Blas on 13 Mar 2020
Commented: Rodrigo Blas on 13 Mar 2020
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;
icdelp=delpo;
%%y=zeros(2,1);
ode=@odes;
xo=[icQ icdelp];
xspan=[0 100];
[X,Y]=ode45(@(x,y)odes(x,y,jw,a1,k2),xspan,xo)
jw=JW(lp,qo,delpio,k3,y,xo,z);
function F=JW(lp,qo,delpio,k3,y,xo,z)
F=fsolve(@findjw,xo);
function F=findjw(z)
F=lp*(y(2)-qo*delpio/y(1)*exp(z/(k3*y(1)^0.40)))-z;
end
end
function dydx=odes(x,y,jw,a1,k2)
%%syms Q(x) P(x)
dydx=zeros(2,1)
dydx(1)=-jw*a1;
dydx(2)=-k2*y(1);
%%dydx1=diff(Q)==-jw*a1;
%%dydx2=diff(P)==-k2*Q;
%%dydx=[-jw*a1;-k2*y(1)];
%%dydx=[dydx1;dydx2]
end
Cannot find an exact (case-sensitive) match for
'jw'
The closest match is: JW in
C:\Users\rodri\AppData\Local\JW.m
Error in mhlro>@(x,y)odes(x,y,jw,a1,k2)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets
args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode,
tspan, y0, options, varargin);
Error in mhlro (line 27)
[X,Y]=ode45(@(x,y)odes(x,y,jw,a1,k2),xspan,xo)
>>
Im trying to find my value for jw which is the answer out of fsolve. This value is dependent on the differential equation function and also within the jw eqution there is a jw which i label as 'z' initially then i change it to jw.
The error i get is above

Answers (1)

Cris LaPierre
Cris LaPierre on 13 Mar 2020
You use the variable jw before it gets defined (in your call to ode45). Also, when defining jw, you also use a variable y which has not yet been defined either.
  1 Comment
Rodrigo Blas
Rodrigo Blas on 13 Mar 2020
jw is the answer from JW() fsolve. the JW() function is dependent on the answer from dydx() function.however jw is also a component of the dydx() function.
these two functions have to be computed simultaneously.
I dont know where to start

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!