I am trying to input an equation with multiple integrals and infinite summations.

1 Ansicht (letzte 30 Tage)
I am trying to input these three equations into MATLAB but I keep getting errors. This is the analytical solution to the 2D Wave Equation.
where
Here is my code:
a = 10; % Boundary of X Axis
b = 10; % Boundary of Y Axis
c = 1; % Speed
w = pi;
Alpha = 0.75;
Sigma = 0.1;
xNot = a/2;
yNot = b/2;
x = 1;
y = 1;
t = 1;
syms n m
P_c = symsum(symsum(4/(c*sqrt(n^2*pi^2/a^2 + m^2*pi^2/b^2)*sin(c*t*sqrt(n^2*pi^2/a^2 + m^2*pi^2/b^2))) + 4*cos(c*t*sqrt(n^2*pi^2/a^2 + m^2*pi^2/b^2))*sin(n*pi*x/a)*sin(m*pi*y/b),n,1,Inf),m,1,Inf);
P_p = integral(@(s) symsum(symsum(4/(a*b*c*sqrt(n^2*pi*2/a^2 + m^2*pi^2/b^2))*integral2(@(x,y) sin(w*s).*exp(-Alpha*s).*exp(-1/Sigma^2*((x-xNot).^2 + (y-yNot).^2))*sin(n*pi*x./a)*sin(m*pi*y./b),0,a,0,b)*sin(c*(t-s).*sqrt(n^2*pi^2/a^2 + m^2*pi^2/b^2))*sin(n*pi*x/a)*sin(m*pi*y/b),n,1,Inf),m,1,Inf),0,t);
P = P_c + P_p;

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Jul. 2020
integral() is only for numeric integrals. For symbolic integrals you need int()
  4 Kommentare
Richard Batelaan
Richard Batelaan am 11 Jul. 2020
Thank you so much for your answer. I have been trying to make a surface in the way that you said, but I cannot figure it out. Here is what I have:
[X,Y] = meshgrid(1:10,1:10);
Ps = subs(Ps,x,X);
Ps = subs(Ps,y,Y);
Ps = subs(Ps,t,3);
Ps = vpa(Ps);
Ps = double(Ps);
surf(X,Y,Ps)
Walter Roberson
Walter Roberson am 17 Jul. 2020
[X,Y] = meshgrid(1:10,1:10);
Pss = subs(Ps, {x,y,t}, {X, Y, 3});
Psd = double(Pss);
surf(X, Y, Psd, 'edgecolor', 'none');
That is, suppose you had the formula F = x + y . Suppose you subs(F, x, 1:3) . Then the result you get back would be [1+y, 2+y, 3+y], Suppose you then subs() y, [4 5 6] into that. Then the 4 5 6 has to go in for each location that y occurs. It will not be substituted for corresponding locations. So you would get [1+4, 1+5, 1+6, 2+4, 2+5, 2+6, 3+4, 3+5, 3+6]
However if you subs(F, {x, y}, {1:3, 4:6}) then MATLAB will do simultaneous substitution of corresponding elements, producing [1+4, 2+5, 3+6]
You were substituting in over multiple steps, so you were getting arrays larger than you expected.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by