Problem with solving an ODE

1 次查看(过去 30 天)
Hello,
When I run the code below, I get an error because the initial condition for y is dependent on Dy. I've seen this case (boundary conditions depend on first derivatives) in a few papers, but I'm not sure how to solve it. Could someone please help me with this?
syms y Dy D2y x Y
y0=(5+Dy*2)/0.49;
ode = y-(1/(Dy/y+(D2y*x)/y))^2;
ode1 = solve(ode==0,D2y)
ode1 = 
ode2 = matlabFunction(ode1(1),'Vars',{x,[y Dy]})
ode2 = function_handle with value:
@(x,in2)(in2(:,1).*(sqrt(1.0./in2(:,1))-in2(:,2)./in2(:,1)))./x
odefcn = @(x,y)[y(2);ode2(x,[y(1),y(2)])];
bcfcn = @(ya,yb)[ya(1)-y0;yb(2)-1];
xmesh = linspace(1e-3,4,10);
solinit = bvpinit(xmesh, [1 1]);
sol = bvp4c(odefcn,bcfcn,solinit);
Unable to perform assignment because value of type 'sym' is not convertible to 'double'.

Error in bvp4c>colloc_RHS (line 543)
Phi(1:nBCs) = Gbc(y(:,Lidx),y(:,Ridx),ExtraArgs{1:nExtraArgs});

Error in bvp4c (line 182)
[RHS,yp,Fmid,NF] = colloc_RHS(n,x,Y,ode,bc,npar,xyVectorized,mbcidx,nExtraArgs,ExtraArgs);

Caused by:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
plot(sol.x,sol.x.*sol.y(1,:))

采纳的回答

Torsten
Torsten 2023-5-17
Use
bcfcn = @(ya,yb)[ya(1)-(5+ya(2)*2)/0.49;yb(2)-1];
instead of
bcfcn = @(ya,yb)[ya(1)-y0;yb(2)-1];
in your code.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by