# Demo entry 6626215

p1

Submitted by anonymous on Jun 23, 2017 at 16:56
Language: Matlab. Code size: 1.1 kB.

```% codei for problem 1
% Matalb 2016b
% date: 23/6/2017
% author:siche

clear all;
clc;
close all;
M =[1.73,2.20,3.11];
A=[0.435,1.31,5.24];
w=0.5;

% code for probelm 1
for k=1:3
X_M=M(k);
a=A(k);
temp=5*X_M;
t=linspace(0,2*pi/w,21);
subplot(3,1,k);
name=['a=',num2str(a)];
title(name);

for j=1:5:21
syms C1 C2 C3 C4 x y;
% solve general equation
%y = dsolve('D4y = -i*y','x');
% general solution:
y = C1*exp(-1i*(-1i)^(1/4)*x)+C2*exp(-((-1i)^(1/4)*x))+C3*exp(-((-1i)^(5/4)*x))+C4*exp((-1i)^(1/4)*x);
% symbolic derivative
y1 = diff(y,1);
y2 = diff(y,2);
y3 = diff(y,3);
y4 = diff(y,4);

% evaluate boundary at x =0
x = 0;
eq1 = vpa(eval(y));
eq2 = vpa(eval(temp*y1+a*i));

x = X_M;

eq3 = vpa(eval(y2));
eq4 = vpa(eval(y3));

[C1 C2 C3 C4] = solve(eq1,eq2,eq3,eq4,C1,C2,C3,C4);

% covert Symbolic to double
C1 = double(C1);
C2 = double(C2);
C3 = double(C3);
C4 = double(C4);

x = 0:0.01:X_M;

yt = eval(vectorize(y))*exp(1i*w*t(j));

% plot figures
% scatter(x./temp,real(yt));
plot(x./temp,real(yt));

hold on;
end
end
```

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.