1. Engineering
  2. Mechanical Engineering
  3. 13 basic matlab function using vectorization and error definitions pts...

Question: 13 basic matlab function using vectorization and error definitions pts...

Question details

1.3 Basic MATLAB function using VECTORIZATION, and ERROR definitions pts You probably already know from calculus that you can write sin(x) -x--- . a) Create a MATLAB function called FUNC1 3.m to calculate the sum of the terms up to the power xV. That is, evaluate S(x,N) (R-I)/2x k! k-13,5.. For example, S(2,11)-2- 23 25 27 29 211 -+ 3 5! 711-0.909296136 Your function FUNC1_3 must accept two inputs (x and N) and output one value representing S(x,N) Whats the catch? NOWHERE in your function can you use FOR or WHILE loops, or IF commands!!! You must think how to do all calculations in a vectorized way, as discussed in class (Hint: maybe create a vector of just the odd values of k from 1 to N; then use MATLABs element-by- element math operators to create a vector in which the elements are (-1 »,/k! ; then use the sum function to add up the terms of the vector. Or, maybe you have another way of doing it. Just dont use for-while-if !!) b) Use your function to demonstrate to yourself that the series converges (as N - for x-π/2. (This should make sense to you because you know sin(a/2)-1) o) to the limit 1 Do the demonstration by using your new MATLAB function to calculate S(x,N) for x pi/2 and N-5, 11 and 17, and you should see the result getting closer to 1 as N gets bigger. Lets define the error as the difference between the exact sin(x) and the approximate S(x,N) Now calculate the errors (i.e. differences between 1 and S(ax/2, N)) for N 5, 11 and 17. Use format long to be sure to capture each of the three errors to at least three significant figures These are the three values youre going to enter into Carmen. You should see these errors get closer to 0 as N gets larger.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution