error ode arguments (line 92)

6 次查看(过去 30 天)
Hello, so I was practicing the shooting method using this script:
function Shooting_Con
option=odeset('RelTol',1e-3)
s=-200:20:200
s0=[]
ncase=length(s)
b=zeros(1,ncase)
for i=1:ncase
[z,c]=ode23s(@mandela,[0 0.001],[0.2 s(i)],option)
%zrange= 0 to 0.001
[m,n]=size(c)
b(1,i)=c(m,2)
end
y0=interp1(b,s,0)
global k Dab
k=.001
Dab=(1.2e-9)
L=.001
x=L*sqrt(k/Dab)
[z c]=ode45(@mandela,[0 0.001],[0.2 y0],option)
C=0.2*(cosh(x*(1-z/L))/cosh(x))
plot(z,C,'r',z,c(:,1),'ko')
legend('Exact','Differential')
xlabel('z')
ylabel('Concentration')
grid on
function dCadz=mandela(z,c)
global k Dab
dCadz=[c(2);((k/Dab)*c(1))]
but when I run it, it returns these errors: Error using odearguments (line 92) MANDELA returns a vector of length 1, but the length of initial conditions vector is 2. The vector returned by MANDELA and the initial conditions vector must have the same number of elements.
Error in ode23s (line 121) = odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in class_0323 (line 8) [z,c]=ode23s(@mandela,[0 0.001],[0.2 s(i)],option) but I have two things in my dCadz function so I don't understand why I am only getting back 1 value when there are two things. :/ I need some serious help.

采纳的回答

Walter Roberson
Walter Roberson 2017-3-26
Your function relies upon two global variables having been set properly. But you do not set those variables before you call ode23 with the function.
Note: global is the slowest kind of variable,not a good choice for a routine that will be called many times. You should learn how to parameterize functions.
  1 个评论
Marlon Brutus
Marlon Brutus 2017-3-26
Thank you so much I didn't realize that, also thanks for the suggestion.

请先登录,再进行评论。

更多回答(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