Unable to troubleshoot this error message

2 Ansichten (letzte 30 Tage)
Foo How
Foo How am 5 Mai 2011
% ODE 45 where n = 0 %
function dy = prob5partb(z,y,n)
%constant declaration%
h = 1.054571628e-34; %reduced planck's constant
Mo = 9.10938188e-31; %rest mass of electron
M = 0.067 * Mo; %effective mass of electron
Uo = 1.60217646e-19; %depth of well
A = 2e-9; %effective well size
%formula of Uz%
U=Uo*(exp(-2*(z/A))-2*exp(-z/A));
%formula of En%
En = -Uo*(1 - (h/(2*M*Uo*A^2)^0.5) * (n + 0.5))^2;
%To create a column vector
dy=zeros(2,1);
%The two first order ode
dy(1) = y(2);
dy(2) = (U - En)*((2 * M * y(1))/(h^2));
end
n = 0;%energy level
[Z,Y]=ode45( @(z,y) prob5partb(z,y,n) , [-1e-8 100e-10] , [0.1 0.5] )%use ode45 with the function wave with limts and initial condition
n0=plot(Z,Y(:,2), ': r');%plot time
hold on;
n = 1;%energy level
[Z,Y]=ode45( @(z,y) prob5partb(z,y,n) , [-1e-8 100e-10] , [0.1 0.5] )%use ode45 with the function wave with limts and initial condition
n0=plot(Z,Y(:,2), ': g');%plot time
hold on;
n = 2;%energy level
[Z,Y]=ode45( @(z,y) prob5partb(z,y,n) , [-1e-8 100e-10] , [0.1 0.5] )%use ode45 with the function wave with limts and initial condition
n0=plot(Z,Y(:,2), ': b' );%plot time
hold on;
Legend('Energy level 0', 'Energy level 1', 'Energy level 2');
function [Z,Y] = RK4(z,y,z1,n,f)
Z = z;
Y = y';
h = (z1 - z)/n;
for i = 1:n;
k1 = f(z,y);
k2 = f(z + h/2, y + k1*h/2);
k3 = f(z+h/2, y + k2*h/2);
k4 = f(z+h, y + k3*h);
y = y + h*(k1 + 2*k2 + 2*k3 + k4)/6;
z = z+h;
Z = [Z;z];
Y = [Y;y'];
end
n=0;
[Z,Y]=RK4(-0.5e-8, [0.1;0.5], 20e-100, 50, @(Z,Y) prob5partb(z,y,n));
n0=plot (Z,Y(:,2), 'y');
hold on;
The error message displayed in the command window:
Error in ==> RK4 at 6
k1 = f(z,y);
Error in ==> RK4G at 2
[Z,Y]=RK4(-0.5e-8, [0.1;0.5], 20e-100, 50, @(Z,Y) prob5partb(z,y,n));
I am at my wit's end in troubleshooting this error, may i know whether would anyone care to enlighten me on this matter thank you. The error message lies with the last two paragraph of the coding.
  1 Kommentar
Walter Roberson
Walter Roberson am 6 Mai 2011
Surely it doesn't just say "Error in" and give a routine and line? Surely it tells you _what_ it thinks the error is?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jarrod Rivituso
Jarrod Rivituso am 6 Mai 2011
I'm not sure, but should
[Z,Y]=RK4(-0.5e-8, [0.1;0.5], 20e-100, 50, @(Z,Y) prob5partb(z,y,n));
really be
[Z,Y]=RK4(-0.5e-8, [0.1;0.5], 20e-100, 50, @(z,y) prob5partb(z,y,n));
*note the lowercase z and y in the anonymous function

Walter Roberson
Walter Roberson am 6 Mai 2011
You have written,
@(Z,Y) prob5partb(z,y,n)
Why are you ignoring the input parameters "Z" and "Y" and instead using what-ever values of "z" and "y" happened to exist at the time the anonymous function was created? Why are you not using
@(Z,Y) prob5partb(Z,Y,n)
??

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by