Hopefully, at this point, you can at least understand how a for-end loop is supposed to work and what it might be used for. You should also start to understand the 3 key concepts you should learn about these loops. It is OK if you are a little shaky in your knowledge, but you should at least know what you need to learn.
Returning to our Maclaurin series example, we are now ready for the code phase. Based on what you have learned about for loops, can you write the MATLAB code that accomplishes our programming goal? To remind you, the goal was:
Create a MATLAB script that can return the value of the Maclaurin series expansion of \(sin(x)\) for angle \(x\) in radians, for an arbitrary \(n\) number of terms.
When we say an arbitrary \(n\) number of terms, your script should allow the user to change a variable n to change how many terms are used in the estimation.
For example, if the user specifies n = 3, and wants to estimate \(sin(1.15)\) by specifying x = 1.15, the program should calculate: (this is actually a pretty good estimate by the way) Give it your best shot! Try and see if you can come up with this code on your own! I believe in you!
If you didnβt get this exactly it is OK as long as you tried. Spend some time with the script above in Example 15.3.2 until you understand how it works. Keep practicing, reading, and watching YouTube video tutorials until this is starting to click!
Does your code work the same as the code above? If it doesnβt, what did you have to chang? What was something you have learned about for loops (or coding in general) by completing this example?