How to pass a known constant vector of specific dimensions to ode() function in bvp4c method.

1 次查看(过去 30 天)
Hi, I need to solve a second order differential equation using bvp4c method,which includes a constant vector 'Gx'.The size of the constant vector is equal to the size of the 'xint' values used in deval() function.The first part of the script is used to find the constant vector 'Gx' which is passed to bvp4c function and used in bvp4ode function.I dont know if its the right way to pass coz the number of x values bvp4ode() function takes to solve the differential equation is not known.When i run the code i get an error of "Too many input arguments".Can someone please tell me how to fix the error and how to use the constant vector in bvp4ode function.Thank you.
function tm
.
.
Gx=...%%Gx is a column vector whose size is equal to size of xint used for plotting in bvp4c(In this case its 50)
.
.
bv(Gx);
end
function bv(Gx)
xlow=1;
xhigh=50;
solinit=bvpinit(linspace(xlow,xhigh,10),[1 -1]);
sol=bvp4c(@bvp4ode,@bvp4bc,solinit,Gx);
xint=linspace(xlow,xhigh,50);
sxint=deval(sol,xint);
figure(4)
plot(xint,sxint(1,:))
disp(sol.x)
end
function dydx=bvp4ode(x,y,Gx)
dydx=[y(2);(y(1)/1e-16)-1e7.*Gx]
end
function res=bvp4bc(ya,yb)
res=[ya(1);yb(1)];
end

回答(2 个)

Kevin Doherty
Kevin Doherty 2015-9-24
Without seeing all of the output I cannot say for certain where the error is occuring. But you have the line
sol=bvp4c(@bvp4ode,@bvp4bc,solinit,Gx);
which is providing bvp4c with four input arguments but bvp4c only accepts one. This could explain the "Too many input arguments" error. But another problem here is that bvp4c is being called within bvp4c! Perhaps you meant to call another function.
  2 个评论
chants sumanth
chants sumanth 2015-9-24
Hi Kevin, I changed the name of function to 'bv' but i get the same error.here i rewrite the code and error.The code and related files are attached
function tm()
.
.
Gx=..
.
bv(Gx)
end
function bv(Gx)
xlow=1;
xhigh=50;
options=[];
solinit=bvpinit(linspace(xlow,xhigh,10),[1 -1]);
sol=bvp4c(@bvp4ode,@bvp4bc,solinit,options,Gx);
xint=linspace(xlow,xhigh,50);
sxint=deval(sol,xint);
figure(4)
plot(xint,sxint(1,:))
disp(sol.x)
end
function dydx=bvp4ode(x,y,Gx)
dydx=[y(2);(y(1)/1e-16)-1e7.*Gx]
end
function res=bvp4bc(ya,yb)
res=[ya(1);yb(1)];
end
error Error using TransferMatrix>bvp4ode (line 284) Not enough input arguments.
Error in bvparguments (line 105) testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 129) [n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
Error in TransferMatrix>bv (line 274) sol=bvp4c(@bvp4ode,@bvp4bc,solinit,Gx);
Error in TransferMatrix (line 250) bv(Gx)
Steven Lord
Steven Lord 2015-9-24
In the Description section of the documentation page for BVP4C there's a link that describes how to pass additional parameters to the functions you specify as your ODE and boundary condition functions. Use the techniques described in that documentation to pass additional parameters into your bvp4ode function.

请先登录,再进行评论。


Varun Gupta
Varun Gupta 2016-5-11
Hi, I have a system of non-linear ODEs with boundary conditions. How can i solve it using bvp4c. I am not able to input all the parameters by converting these into 4 first order ODEs

类别

Help CenterFile Exchange 中查找有关 Boundary Value Problems 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by