How can I plot the following in MATLAB?

1 view (last 30 days)
Hello Everyone! Could anyone help me plot the following Fourier Cosine series,
,
where the fourier cosine coefficients are
,
, .
I tried the following code for a specific value of n=8 just to check it but it does not give me the correct results.
clear all, clc
syms x t k
for t=0:0.5
bo=1.40985;
bl=-0.443179;
t1=exp(-(k^2)*(pi^2)*t);
t2=k*sin(k*pi*x);
t3=cos(k*pi*x);
S1=symsum((bl*t1*t2),k,1,8);
S2=symsum((bl*t1*t3),k,1,8);
S3=bo+S2;
S4=S1/S3;
u=((-pi)*S4);
end
fplot(u)

Accepted Answer

David Hill
David Hill on 3 Jun 2020
Not sure if this is what you are looking for or not.
for n=0:8
f=@(x)exp((1-cos(pi*x))/pi.*cos(n*pi*x));
b(n+1)=2*integral(f,0,1);
end
b(1)=b(1)/2;
[x,t]=meshgrid(0.09:.0001:.1,0:.0001:.01);
n=zeros(size(x));
d=zeros(size(x));
for bb=2:9
n=n+b(bb)*exp(-bb^2*pi^2*t)*bb*sin(bb*pi*x);
d=d+b(bb)*exp(-bb^2*pi^2*t)*cos(bb*pi*x);
end
d=ones(size(x))*b(1)+d;
u=-pi*n./d;
surf(x,t,u,'EdgeColor','none');
  2 Comments
Haseeb Ur Rehman
Haseeb Ur Rehman on 4 Jun 2020
Thanks David Hill for your help. Much appreciated. I guess I am pretty much close to the desired result.
However, I would like to know that how could I plot it for and without altering the for loop for , as I want it to generate the values by adding just first 8 terms in the summation of equation. Though I tried it but I have got the error that "incorrect matrix dimensions for multiplication".
David Hill
David Hill on 6 Jun 2020
for n=0:8
f=@(x)exp((1-cos(pi*x))/pi.*cos(n*pi*x));
b(n+1)=2*integral(f,0,1);
end
b(1)=b(1)/2;
[x,t]=meshgrid(0:.2:1,0:.02:1);
n=zeros(size(x));
d=zeros(size(x));
for bb=2:9
n=n+b(bb)*bb*exp(-bb^2*pi^2*t).*sin(bb*pi*x);%.* element-wise
d=d+b(bb)*exp(-bb^2*pi^2*t).*cos(bb*pi*x);%.* element-wise
end
d=ones(size(x))*b(1)+d;
u=-pi*n./d;
surf(x,t,u,'EdgeColor','none');

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!