speed for loop in sum
    5 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
Can the for loop be removed  ?
x=linspace(-2,2,100); %some vector
[X,XX]=meshgrid(x,x); %some matrix
a=1/2;%some constant
A0=zeros(size(X));%initialize the sum
A0k = @(k,X,a)(((-1)^k).*((X./a).^(2*k)).*besselj(2*k,X));%series
for l=0:20
    A0 = A0+A0k(l,X,a); %sum of series
end
2 Kommentare
Akzeptierte Antwort
  Torsten
      
      
 am 11 Mär. 2019
        function main
  x = linspace(-2,2,100); %some vector
  [X,XX] = meshgrid(x,x); %some matrix
  k = 0:20;
  a = 0.5;
  A0 = arrayfun(@(x)sum((-1).^k.*(x/a).^(2*k).*besselj(2*k,x)),X)
end
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

