Question
Write short MATLAB m-files to solve the following problem involving flow control programming structures. NOTE: Your programs must be silenti.e., they should not echo any
Write short MATLAB m-files to solve the following problem involving flow control programming structures.
NOTE: Your programs must be silenti.e., they should not echo any information to the screen other than that specified in the problem statement (e.g., error trapping messages). This includes any input prompt strings, MATLAB-generated warning or error messages, or intermediate/final results of your own programs calculations.
1. The trigonometric sine function can be expressed as the following infinite Taylor series:
Use the for loop control structure to write a MATLAB function m-file that evaluates the first n terms of this series. Your function should be defined as follows:
function [sinx, ea, error] = mysin(x,n)
% input parameter
% x = input angle in radian
% n = number of terms in the Taylors series (5 in above example)
% output parameter
% sinx = the value of sin(x) using the number of terms specified
% ea = approximate error in percentage
% error= exact error in percentage: (sin(x)sinx)/sin(x)*100
Although you may assume that the input arguments passed to your function will be numeric, your function should trap for invalid input argument values (e.g., nonpositive and/or noninteger values for n); if your program detects invalid input, it should display an appropriate error message and stop. You may not use the MATLAB built-in sin trigonometric function in your program, except to calculate the exact error. Name your submitted file mysin.m.
NOTE: Even though the sine function is harmonic, this series approximation converges very slowly for very large values of x. Consequently, you may assume in your program that the input value is limited to the range 0 ? x ? 2? .
sin(nr) = a l |+ . || +Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started