Plot double Fourier series in MATLAB

7 次查看(过去 30 天)
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
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
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.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by