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

조회 수: 4 (최근 30일)
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)

답변 (1개)

madhan ravi
madhan ravi 2020년 5월 7일
편집: madhan ravi 2020년 5월 7일
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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by