# Plot double Fourier series in MATLAB

22 ビュー (過去 30 日間)
Amin Ghasemi 2016 年 11 月 10 日

I'd like to plot 'mesh' for both f and g functions in MATLAB.
I'd tried this for f and g:
clc
clear
close all
%%plot f
[x,y] = meshgrid(linspace(-pi,pi,50));
f=x.*y ;
subplot(1,2,1)
mesh(f)
title('f')
%%plot g
A=4*(-1)^(m+n)*(sin(m.*x)*sin(n.*y))/(m*n);
g=sum(sum(A,n,1,inf),m,1,inf);
subplot(1,2,2)
mesh(g)
title('g')
The result is:
I don't have any idea to plot g directly from its' function, any help would be appreciated.

サインインしてコメントする。

### 採用された回答

Amin Ghasemi 2016 年 11 月 11 日
finally I found the solution, thanks all.
clc
clear
close all
%%plot f
[x,y] = meshgrid(linspace(-pi,pi,40));
f=x.*y ;
subplot(1,2,1)
mesh(f)
title('f(x,y)=xy')
%%plot g
syms m n X Y
assume(m>=1);
assume(n>=1);
assume(X>-pi & X<pi);
assume(Y>-pi & Y<pi);
A = 4*(-1)^(m+n)*(sin(m*X)*sin(n*Y))/(m*n);
g = real(double(subs(symsum(symsum(A,n,1,Inf),m,1,Inf),{X,Y},{x,y})));
subplot(1,2,2)
mesh(g)
title('g: Double Fourier series of f for -\pi to \pi ')

サインインしてコメントする。

### その他の回答 (1 件)

Daniel kiracofe 2016 年 11 月 11 日
I think your problem is this line
A=4*(-1)^(m+n)*(sin(m.*x)*sin(n.*y))/(m*n);
from the way you have written it, it looks like you are expecting matlab to treat 'm' and 'n' as symbols here, for later evaluation in the sum command. But by default, matlab does not do symbolic computation. it does numeric computation. it is expecting m and n to be numbers (or vectors, or matrices). I think what you wanted to do was to first declare m and n to be symbols (i.e "syms n m"), and then use symsum() instead of sum(). Look up the documentation for the symbolic math toolbox for more information.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by