help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

error "can't perform indexing operations for <unknown type> type"


From: cmire
Subject: error "can't perform indexing operations for <unknown type> type"
Date: Sat, 15 Oct 2005 13:47:14 -0500
User-agent: KMail/1.6.2

I'm new to Octave, and I've got a short Matlab program from a professor that 
we are supposed to modify to solve some homework problems.  I've read that 
Octave can run Matlab code (I've updated the ~/octaverc file accordingly, 
etc.).

When I try to run the code using the command "source(Exercise.m)", I get the 
output:

length = 10
npoints = 200
mass = 0.070000
num_sol = 4
error: can't perform indexing operations for <unknown type> type
error: evaluating argument list element number 1

I don't need help with the actual homework assignment -- I just need to get 
this code working so I can proceed to do my homework.  Help is greatly 
appreciated!

Here is the main program:

%numerical solution to Schroedinger equation for
%rectangular potential well with infinite barrier energy
clear
%clf;

length = 10 %length of well (nm)

npoints=200 %number of sample points

x=0:length/npoints:length; %position of sample points

mass=0.07 %effective electron mass

num_sol=4 %number of solutions sought

for i=1:npoints+1; v(i)=0; end

%potential (eV)

%function solve_sch(length,npoints,v,mass,num_sol)
[energy,phi]=solve_sch(length,npoints,v,mass,num_sol); %call solve_sch

for i=1:num_sol
sprintf(['eigenenergy (',num2str(i),') = ',num2str(energy(i)),' eV']) %energy 
eigenvalues
end

figure(1);
plot(x,v,'b');xlabel('Distance (nm)'),ylabel('Potential energy, (eV)');
ttl=['Chapt3Exercise7, m* = ',num2str(mass),'m0, Length = 
',num2str(length),'nm'];
title(ttl);

s=char('y','k','r','g','b','m','c'); %plot curves in different colors

figure(2);
for i=1:num_sol
j=1+mod(i,7);
plot(x,phi(:,i),s(j)); %plot eigenfunctions

hold on;
end
xlabel('Distance (nm)'),ylabel('Wave function');
title(ttl);
hold off;


And here is the function file for function solve_sch called in the main 
program:

function [e,phi]=solve_schM(length,n,v,mass,num_sol)
% Solve Schrodinger equation for energy eigenvalues and eigenfunctions.
% [energy, phi_fun]=solve_sch(length,number,potential,mass,sol_num)
% solves time-independent Schrodinger equation in region bounded by 
0<=x<=length.
% Potential is infinite outside this region.
%
% length                        length of region (nm)
% n                             number of sample points
% v                             potential inside region (eV)
% mass                  effective electron mass
% sol_num               number of solutions sought
%
% e                             energy eigenvalue (eV)
% phi                           eigenfunction with eigenvalue = e
%
hbar=1.054571596;               %Planck's constant (x10^34 J s)
hbar2=hbar^2;
echarge=1.602176462;            %electron charge (x10^19 C)
baremass=9.10938188;            %bare electron mass (x10^31 kg)

const=hbar2/baremass/echarge;   %(hbar^2)/(echarge*1nm^2*m0)
const=const/mass;               %/m-effective
deltax=length/n;                %x-increment = length(nm)/n
deltax2=deltax^2;
const=const/deltax2;

for i=2:n
d(i-1)=v(i)+const;              %diagonal matrix element
offd(i-1)=const/2;              %off-diagonal matrix element
end

t1=-offd(2:n-1);
Hmatrix=diag(t1,1);             %upper diagonal of Hamiltonian matrix
Hmatrix=Hmatrix+diag(t1,-1);    %add lower diagonal of Hamiltonian matrix

t2=d(1:n-1);
Hmatrix=Hmatrix+diag(t2,0);     %add diagonal of Hamiltonian matrix

[phi,te]=eigs(Hmatrix,num_sol,'SM');    %use matlab function eigs to find 
num_sol eigenfunctions and eigenvalues

for i=1:num_sol
e(i)=te(i,i);                   %return energy eigenvalues in vector e
end
phi=[zeros(1,num_sol);phi;zeros(1,num_sol)]; %wave function is zero at x = 0 
and x = length
return

ΓΏ



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]