Sketch the analytical solution, using the formula below. HELP

1 view (last 30 days)
clear all
for n=2:n
I am getting the error mesage "Index exceeds the number of array elements (1)." What am I doing wrong, please help

Accepted Answer

John D'Errico
John D'Errico on 19 Dec 2021
Edited: John D'Errico on 19 Dec 2021
I might guess that you actually meant to MULTIPLY t with the value (n-1) in this exprssion:
Instead, remember that MATLAB does not have implicit multiplication. You need to use the * or the .* operator as appropriate. Here, it will not matter which you use.
As well, I would suggest that this next line of code is an incredibly bad idea:
for n=2:n
MATLAB does not charge you more, if you use a different variable name. MATLAB will not be more efficient. Reusing the same variable name there is going to cause you innumerable headaches.
What else? I think you have a problem in your code, because you NEVER actually define x(2). You defined x(1). Then your loop starts at n==2. Therefore the first time through the loop, you define x(n+1), where n = 2. So you defined x(3) as the next element. x(2) was never defined. However, you will use x(2) later on.
I predict this code will produce arbitrarily useless strangeness. But that is just a guess. And since we were never told what the actual forumula you want to produce, we are merely guessing.

More Answers (1)

Image Analyst
Image Analyst on 19 Dec 2021
t is a scalar with value 0.6283. There is no second or third element of t so you can't index t with (n-1).

Community Treasure Hunt

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

Start Hunting!

Translated by