How can I plot the following in MATLAB?

1 Ansicht (letzte 30 Tage)
Haseeb Ur Rehman
Haseeb Ur Rehman am 3 Jun. 2020
Kommentiert: David Hill am 6 Jun. 2020
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)

Akzeptierte Antwort

David Hill
David Hill am 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 Kommentare
Haseeb Ur Rehman
Haseeb Ur Rehman am 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 am 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');

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by