Index exceeds the number of array elements (1).

1 次查看(过去 30 天)
I am trying to generate a graph for the analytical expression I got and I used for loop since my solution is in summation but i am getting the error
Index exceeds the number of array elements (1).
here is the expression, please help me to rectify the error
for n=0:1:N
d=a.*pi.*(-1).^n.*(2.*n + 1).*sin(sqrt(m./r).*(x - 1)).*exp(-(a + pi.^2.*(2.*n + 1).^2./4).*t)./(m.*(a.*r - m.*(r - 1)).*sin(sqrt(m./r))) - 2.*a.*(((-1).^n.*sin(n.*pi.*(x - 1))./(n(a.*r - n.^2.*pi.^2.*r.*(r - 1)).*cosh(sqrt(-n.^2.*pi.^2.*r + a))) - sin(n.*pi.*x)).*exp(-n.^2.*pi.^2.*r.*t) + (r - 1).*(2.*sin(sqrt(a./(r - 1)).*(x - 1))./sin(2.*sqrt(a./(r - 1))) - sin(sqrt(a./(r - 1)).*x)./sin(sqrt(a./(r - 1))) + cos(sqrt(a./(r - 1)).*x)./cos(sqrt(a./(r - 1)))).*exp(-a.*r.*t./(r - 1))./r)./pi;
end

采纳的回答

Cris LaPierre
Cris LaPierre 2023-3-31
I suspect the error is that you forgot to include a multiply in this statement after n
(n(a.*r - n.^2.*pi.^2.*r.*(r - 1))
% Should probably be
(n*(a.*r - n.^2.*pi.^2.*r.*(r - 1))
% ^
  3 个评论
Torsten
Torsten 2023-4-17
I'm getting NaN values when setting x = t = 1 (see above).
What are x and t in your case ?
Note that a=mu./1+k; is most probably wrong. I guess you wanted to set a=mu./(1+k);
I didn't look through the formula for d for similar errors.
Cris LaPierre
Cris LaPierre 2023-4-17
We have to assume the code you have shared is accurate. We have no way of knowing what it should be.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by