Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m debugging code that our teacher gave us and I\'m basically stuck at line 13

ID: 3802455 • Letter: I

Question

I'm debugging code that our teacher gave us and I'm basically stuck at line 13 where it tells me that the index exceeds matrix dimensions (see pictures below) It's either j or i but I have no idea what to change and I know this sounds like a dumb question but any help would be appreciated! Thank you!

(This is MATLAB by the way).

2 clear; clc 3 n 2 5 501 5 nn-720 6 angle linspace (-2 pi, 2 *pi, nn) 8 L for j 1:720 z n (j) for i F1:nn-1 10 for k 1 z ns 2 +1 12 S (j, i) S (j, i) (1) k* (angle (i) (ns) factorial (ns) 14 end end 16 end 17 18 19 yl sin (angle) 20 3 0; 21 22 clf grid On 23 hold. on 24 plot (angle yl, 'b', angle, S (1 g', angle, y3 k', 'LineWidth' 2 25 plot (angle, S (2 m', agle, S (3, --y', "Line Width' ,2 26 hold. off 27 axis (C-2 pi 2 pi -1.5 1 5]) 28 xlabel ('Angle (rad) 29 ylabel ('sin (x) 30 title ('Taylor Series Approximation of Sine

Explanation / Answer

in line 4

you have intialized the variable S with value 1

so, after this line,variable S is not an array, it is variable that has value 1(also consider has a two dimension 1X1 matrix)

means: S index bounds are only S(1,1)//because it has only one value...

now in Line 14

again you calling it with S(j,i)

here j,i values ranges from 1 to 720,

but S has only one value that is S(1,1)

so, all the remaining values of j,i are exceeding the index bound of S

that is why you are getting this error

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote