Professional Documents
Culture Documents
%HW 6
%Laura Novoa
Problem 2
%plot u(x,0), u(x,1) and u(x,2)
figure
ezplot(heaviside(x)*sin(x), [0, 10]) %y=0
hold on
ezplot(heaviside(x-1)*sin(x-1)*exp(-1), [0, 10]) % y=1
hold on
ezplot(heaviside(x-2)*sin(x-2)*exp(-2), [0, 10]) % y=1
legend('y=0','y=1','y=2')
title('\itu(x,y) = H(x-y)*sin(x-y)*exp(-y)')
ylabel('\itu(x,y)')
axis auto
Problem 4
%Compute and plot u(x, y) for a = b = 1 and f(x) = x ? x^2
clear all
clc
close all
N=30;
a=1;
b=1;
L = 1;
%Definition of the function to be simulated
syms x
f = x -x.^2;
%Fourier cosine coefficients
for j=1:N
Q(j)=double(int(f*cos((j)*pi*x/a),0, a))*(2/(cosh((j)*pi*b/a)));
end
Q_0 = 2/a*double(int(f,0,a));
%X-vector for plotting
xx=(0:0.01*L:L);
%Reconstruction of the function
fsim=0;
for j=1:N
fsim=fsim + Q(j)*cosh((j)*pi/a*b)*cos((j)*pi/a.*xx);
end