I've tried using a for loop but I was getting an error because my summation starts at 0 which is not allowed
How can I express this very long summation in Matlab? I'm having trouble
4 views (last 30 days)
Show older comments
I'm looking to plot the velocity contours of a fluid flow over a cross section (part e). I already have the two variables (eta and zeta) and I also know their bounds so I was able to succesfully setup the meshgrid. Now I just need to write my function but I am blanking out hard. Is there an easy way to express everything to the right of the summation in Matlab? Also, the summation does not have to go from 0 to infinity, my teacher said it's fine to evaluate just the first 5 terms. I would really appreicate any input.
4 Comments
Walter Roberson
on 25 Mar 2020
A for loop starting from 0 is not a problem.
If you need to use the for loop value as an index, add 1 to it to get the index.
Accepted Answer
David Hill
on 25 Mar 2020
I believe that below should work for you. I did not try it out since you did not provide all the information, but you have to compute the calculation for each (eta,zeta) pair in the meshgrid.
m=0:10;
[eta,zeta]=meshgrid()
for k=1:size(eta,1)
w(k,:)=arrayfun(@(et,ze)K*b^2/2*(1-et^2-4*(2/pi)^3*sum((-1).^m.*cosh((2*m+1)*pi*a*ze/2/b).*...
cos((2*m+1)*pi*et/2)./((2*m+1).^3.*cosh((2*m+1)*pi*a/2/b)))),eta(k,:),zeta(k,:));
end
3 Comments
David Hill
on 25 Mar 2020
It works and runs for me. I did not know what the constants were, so I set them to 1.
m=0:10;
[eta,zeta]=meshgrid(-0.5:0.005:0.5,-1:0.005:1);
K=1;
b=1;
a=1;
w=zeros(size(eta));
for k=1:size(eta,1)
w(k,:)=arrayfun(@(et,ze)K*b^2/2*(1-et^2-4*(2/pi)^3*sum((-1).^m.*cosh((2*m+1)*pi*a*ze/2/b).*...
cos((2*m+1)*pi*et/2)./((2*m+1).^3.*cosh((2*m+1)*pi*a/2/b)))),eta(k,:),zeta(k,:));
end
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!