Azzera filtri
Azzera filtri

error ode arguments (line 92)

6 visualizzazioni (ultimi 30 giorni)
Marlon Brutus
Marlon Brutus il 26 Mar 2017
Commentato: Marlon Brutus il 26 Mar 2017
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.

Risposta accettata

Walter Roberson
Walter Roberson il 26 Mar 2017
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 Commento
Marlon Brutus
Marlon Brutus il 26 Mar 2017
Thank you so much I didn't realize that, also thanks for the suggestion.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by