MATLAB Help!
Anyone willing to help solve this? I'm pretty confused on how to start them. The teaching is horrible...
1. The function e<sup>x</sup> or exp(x) can be approximated using the Maclaurin Series (a specific type of Taylor Series) as follows (do ? "factorial"):
For a user supplied absolute percent error, abs_per_error, write Matlab code using a "while" loop to calculate exp_mac using the Maclaurin Series for x=12. Run the calculation (the loop) until exp_mac is within abs_per_error of the value generated by the Matlab function exp(x). The absolute percent error, abs_loop_error, is calculated each time through the loop as follows: 100*(abs((exp(x)-exp_mac))/exp(x)). Use fprintf with %2.8f to display the final values of exp_mac and exp(x), use %1.6f to display the final percent error, and use %d to display how many steps were needed to reach the target percent error.
2. In a single m-file (disp(yourname)), using "while" loops, do the following (your m-file will have 5 separate pieces of code for (a) thru (e)):
1. The function e<sup>x</sup> or exp(x) can be approximated using the Maclaurin Series (a specific type of Taylor Series) as follows (do ? "factorial"):
For a user supplied absolute percent error, abs_per_error, write Matlab code using a "while" loop to calculate exp_mac using the Maclaurin Series for x=12. Run the calculation (the loop) until exp_mac is within abs_per_error of the value generated by the Matlab function exp(x). The absolute percent error, abs_loop_error, is calculated each time through the loop as follows: 100*(abs((exp(x)-exp_mac))/exp(x)). Use fprintf with %2.8f to display the final values of exp_mac and exp(x), use %1.6f to display the final percent error, and use %d to display how many steps were needed to reach the target percent error.
2. In a single m-file (disp(yourname)), using "while" loops, do the following (your m-file will have 5 separate pieces of code for (a) thru (e)):
- sum random integers between 1 & 13 (playing card numbers) until the sum is greater than 40. Let the sum echo to the command window.
- repeat (a) and keep track of how many draws were required to exceed 40. Use fprintf to print the number of draws to the screen.
- repeat (a), only if an 8 is drawn, jump out of the loop and fprintf that the program was terminated since an 8 was drawn
- repeat (b), only if an 8 is drawn jump back to the top of the loop without including the 8 in sum.
- repeat (a) only make each element of a vector, z, equal to the previous element plus the random integer, again until the sum exceed 40. So, y(1)=0; y(2)=y(1)+1<sup>st</sup> random integer, etc. – doing this in a "while" loop (repeat in a "for" loop on your own.)
0
Comments