How to plot analytical solution in terms of Fourier Series

조회 수: 5 (최근 30일)
Muhammad Usman
Muhammad Usman 2019년 11월 6일
답변: Koushik Kureti 2020년 3월 5일
I want to plot the analytical solution of the equation given below:
for x=-1:1 and t=0:0.4:2 for as suitable values of p.
I tried to write the code as:
function adv_fourier()
x = linspace(-1,1);
niu=1/100*pi;
c=0.001;
% p=1;
syms n p
t=0:0.4:2;
for i=1:numel(t)
A = @(n) (((-1)^p)*2*p*sin(p*pi*x)*exp(-niu*(p^2)*(pi^2)*t(i)))./((c^4)+8*((c*pi*niu)^2)*((p^2)+1)+16*((pi*niu)^4)*((p^2)-1)^2);
A_sum = symsum(A(p),p,1,50);
B = @(n) (((-1)^p)*(2*p+1)*cos(((2*p+1)/2)*pi*x)*exp(-niu*(((2*p+1)/2)^2)*(pi^2)*t(i)))/((c^4)+((c*pi*niu)^2)*(8*(p^2)+8*p+10)+((pi*niu)^4)*((4*(p^2)+4*p-3))^2);
B_sum = symsum(B(p),p,1,50);
S = (sinh(c/(2*niu)).*(A_sum) + cosh(c/(2*niu)).*(B_sum));
u = 16*(pi^2)*(niu^3)*c*exp((c/(2*niu))*(x-0.5*c*t(i))).*S;
plot(x,u);
grid on
hold on
end
end
But it is not genrating the desired results. Please suggest me suiable changes. Thanks

답변 (1개)

Koushik Kureti
Koushik Kureti 2020년 3월 5일
Hello Usman,
Your MATLAB code is working all good, however, I see you are not able to generate the desired results. You can get the desired results by correcting your code at B(exponential part's denominator)as
B = @(n) (((-1)^p)*(2*p+1)*cos(((2*p+1)/2)*pi*x)*exp(-niu*(((2*p+1)/4)^2)*(pi^2)*t(i)))/((c^4)+((c*pi*niu)^2)*(8*(p^2)+8*p+10)+((pi*niu)^4)*((4*(p^2)+4*p-3))^2);
The highlighted (bold and underlined) is the correction you should make for better results.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by