필터 지우기
필터 지우기

error ode arguments (line 92)

조회 수: 6 (최근 30일)
Marlon Brutus
Marlon Brutus 2017년 3월 26일
댓글: Marlon Brutus 2017년 3월 26일
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