You are on page 1of 12

%MAE 200B

%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

%Adding Q_o/2 to the cosine series


fsim = Q_0/2 + fsim;
%Plot of original and simulated function
close
figure('Position',[20,150,700,300],'Color','w')
subplot('Position', [0.10,0.18,0.85,0.73])
ezplot(f, [0,L])
hold on
plot(xx, fsim, 'linewidth', 1.5, 'color', 'r')
hold off
%axis([0,L, -0.5, 0.5])
axis auto
grid on
set(gca,'fontsize',11)
xlabel('{\it x/L}','FontName', 'Times','FontAngle', 'normal','fontsize',16);
ylabel('{\it f}','FontName', 'Times','FontAngle', 'normal','fontsize',16);
legend('Original function', ['Simulated function (', num2str(N), ' terms)'], -1)

%X,Y mesh for plotting


[X,Y] = meshgrid(0:0.01*L:L,0:.01:1);
%Reconstruction of the function
fsim=0;
for j=1:N
fsim=fsim + Q(j)*cosh((j)*pi/a.*(Y-b)).*cos((j)*pi/a.*X);
end
U = Q_0/2 + fsim;
figure
mesh(X,Y,U)
xlabel('x')
ylabel('y')
zlabel('u')

Published with MATLAB R2015a

You might also like