How to plot analytical solution in terms of Fourier Series

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Koushik Kureti
Koushik Kureti il 5 Mar 2020
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.

Community Treasure Hunt

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

Start Hunting!

Translated by