Attempting to sum over i, with linspace'd variable x, to plot increase in y with x

4 views (last 30 days)
As the title says, I'm trying to iterate over i, while continuously varying x.
But I don't want a plot for each and every i...
It doesn't seem to want to use the final cumulative y in the plot, which I in vain attempted to solve with disp(y).
n= 33;
x = linspace(0, 0.1);
for i=1:n
y = y+(2/pi)*(((-1)^(i+1)+1)/i)*(sin(i*pi*0.005/.01))*(cosh(i*pi*x)/1)/(cosh(i*pi));
disp(y)
end
plot(x, y)

Answers (1)

madhan ravi
madhan ravi on 7 May 2020
Edited: madhan ravi on 7 May 2020
n = 33;
x = linspace(0, 0.1);
ii = 1:n
y = cumsum((2/pi)*(((-1).^(ii+1)+1)./ii).*(sin(ii*pi*0.005/.01))...
*(cosh(ii*pi.*x(:))/1)./(cosh(ii*pi)));
plot(x,y)
Examine what happens:
%% Example
x1 = 1:5
ii1 =
x1(:) .* ii1

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!