Index exceeds the number of array elements (1).

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Cris LaPierre
Cris LaPierre il 31 Mar 2023
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 Commenti
Torsten
Torsten il 17 Apr 2023
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 il 17 Apr 2023
We have to assume the code you have shared is accurate. We have no way of knowing what it should be.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by