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

5 views (last 30 days)
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

Answers (2)

Kevin Doherty
Kevin Doherty on 24 Sep 2015
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 Comments
chants sumanth
chants sumanth on 24 Sep 2015
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 on 24 Sep 2015
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.

Sign in to comment.


Varun Gupta
Varun Gupta on 11 May 2016
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

Tags

Community Treasure Hunt

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

Start Hunting!