schqd - for j = 1:x_d for k = -1000:1000 if(k~=0) %...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
%This function plots the solution to the Schr\”{o}dinger wave equation. First, save the file in a suitable folder and change the matlab environment to that particular folder. One can call the function by giving a suitable value for the time and position, note here that the position is an array of numbers. function [ result ] = schrqd( t,x )%Name of the function. dmn = size(x);%Size of the position array. x_d = dmn(2); result = zeros(size(x));%Providing the size of ‘result’. sum_t = zeros(size(x));%Providing the size of ‘sum_t’ %For loop to recursively compute the solution.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for j = 1:x_d for k = -1000:1000 if(k~=0) % evaluating the case when $k = 0$. sum_t(j) = sum_t(j) + ((-1)^k)/k*exp(1i*(k*x(j) +k^2*t)); end end end %For loop to compute the final solution. for k = 1:x_d result(k) = (1/(2*pi*1i))*sum_t(k); end plot(x,real(result));% Plot the solution xlabel('x','FontSize',14); % Labeling the x axis ylabel('\psi(t,x)','FontSize',16);% Labeling the y axis title('Solution to the Schrodinger wave equation ','FontSize',16); % Providing the title to the graph. end...
View Full Document

This note was uploaded on 11/19/2011 for the course MATH 101 taught by Professor Wormer during the Spring '08 term at UCSD.

Ask a homework question - tutors are online