Odd symsum, loop or another way?

2 Ansichten (letzte 30 Tage)
Matlabnoob12314
Matlabnoob12314 am 26 Jun. 2020
Beantwortet: Walter Roberson am 26 Jun. 2020
Hi,
im looking for a way to sum only the odd numbers of this expression:
[x,y] = meshgrid(-1:0.1:1,-1:0.1:1);
u = zeros(size(x));
syms k;
f = -(16./pi.^3.*(sin(k.*pi.*(1 + x))./2)./((k.^3).*sinh(k.*pi))).*((sinh(k.*pi.*(1 + y))./2) + (sinh(k.*pi.*(1-y))./2));
u = double((1 - x.^2)./2 + symsum(f, k, 1,10));
surf(x,y,u);
..and im pretty lost on how to do it. Do i need to construct a loop for the symsum and how would i go about it?

Akzeptierte Antwort

darova
darova am 26 Jun. 2020
use numerical approach
[x,y,k] = meshgrid(-1:0.1:1, -1:0.1:1, 1:2:5);
u = zeros(size(x));
f = -(16./pi.^3.*(sin(k.*pi.*(1 + x))./2)./((k.^3).*sinh(k.*pi))).*((sinh(k.*pi.*(1 + y))./2) + (sinh(k.*pi.*(1-y))./2));
u = double((1 - x(:,:,1).^2)./2 + sum(f,3);
surf(x(:,:,1),y(:,:,1),u);
  1 Kommentar
Matlabnoob12314
Matlabnoob12314 am 26 Jun. 2020
Pretty sure that worked, though one line has a missing ). Thank you a bunch for a quick reply and the solution.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 26 Jun. 2020
[x,y] = meshgrid(-1:0.1:1,-1:0.1:1);
u = zeros(size(x));
syms k K;
f = -(16./pi.^3.*(sin(k.*pi.*(1 + x))./2)./((k.^3).*sinh(k.*pi))).*((sinh(k.*pi.*(1 + y))./2) + (sinh(k.*pi.*(1-y))./2));
u = double((1 - x.^2)./2 + symsum(subs(f, k, 2*K-1), K, 1,5));
surf(x,y,u);

Community Treasure Hunt

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

Start Hunting!

Translated by