How to pass a known constant vector of specific dimensions to ode() function in bvp4c method.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (2)
Kevin Doherty
am 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 Kommentare
Steven Lord
am 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.
Varun Gupta
am 11 Mai 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Boundary Value Problems finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!