Homework one for MATLIB(Due:11:00 pm March.1) 1.Temperature conversion Write a script that outputs a table of degrees Fahrenheit and degrees Centigrade starting with-40 degrees Fahrenheit,ending with 140 degrees Fahrenheit in increments of 10 degree Fahrenheit.The conversion from degrees Fahrenheit to degrees Centigrade is: C=(F-32)*5/9 You should do it in MATLAB way. Function Declaration: Function C=f2c (F) Sample output: Tempreture Convertion Table Fahrenheit Centigrade -40 -40.0 -30 -34.4 -20 -28.9 -10 -23.3 0 -17.8 130 54.4 140 60.0 Although only the data matters,you still should try your best to follow the format Notes for submission: You should save your homework in an m file and submit your homework to the Sakai using attachment. Name you file in the following matter.The format is important,if you did not follow this rule, your homework may not be able to be grated correctly or on time. sYourlD_hwk1_1.m Example s5073709022hwk1_1.m
Homework one for MATLIB (Due: 11:00 pm March. 1) 1. Temperature conversion Write a script that outputs a table of degrees Fahrenheit and degrees Centigrade starting with -40 degrees Fahrenheit, ending with 140 degrees Fahrenheit in increments of 10 degree Fahrenheit. The conversion from degrees Fahrenheit to degrees Centigrade is: C = (F − 32) * 5 / 9 You should do it in MATLAB way. Function Declaration: Function C = f2c (F) Sample output: Although only the data matters, you still should try your best to follow the format Notes for submission: You should save your homework in an m file and submit your homework to the Sakai using attachment. Name you file in the following matter. The format is important, if you did not follow this rule, your homework may not be able to be grated correctly or on time. sYourID_hwk1_1.m Example : s5073709022_ hwk1_1.m
2.Turn pseudo-code into real code Write a MATLAB code to find the zero of a function.Your code will be made up of three M-files: a script M-file to drive the process a function M-file that finds zeros using a Newton procedure (explained below) a function M-file that contains the function for which you are finding the zero. Pseudo-code for the three pieces is given below.Construct the MATLAB code. Script M-file (a)Prompt the user for an initial guess for the x value at which the zero occurs. (b)Call the zero-finding function,with the initial guess as the input argument,and the final answer and number of steps it took to find the final answer as the output arguments. (c)Print out the final answer and the number of steps it took to find the final answer in some self-explanatory format. Function M-file for finding a Zero (a)This function has one input argument,the initial guess for x. (b)This function has two output arguments,the final approximation of the xvalue at which the zero is found,and the number of steps it took to find it. (c)Set a convergence criterion of s=10-6. (d)Initialize the number of iterations to zero. (e)Carry out the following steps until the absolute value of f(x)<&where f is the function you are zeroing,and x is your current approximation of the zero. Calculate an approximation to the derivative of the function at this point,from f(c)=f(r+e)-f(c-) 2e Calculate a new approximation to the zero,from x=x-f(x)/f(x) Update the number of steps that you have taken through the loop. (⑤Return to main Hint:Function Prototype function [x n]findZero (initGuess) Function M-file f (a)This function has one input argument,x. (b)This function has one output argument,y. (c)The relation is y=x2-sin()/x; Hint:Function Prototype function y=yValue (x)
2. Turn pseudo-code into real code Write a MATLAB code to find the zero of a function. Your code will be made up of three M-files: • a script M-file to drive the process • a function M-file that finds zeros using a Newton procedure (explained below) • a function M-file that contains the function for which you are finding the zero. Pseudo-code for the three pieces is given below. Construct the MATLAB code. Script M-file (a) Prompt the user for an initial guess for the x value at which the zero occurs. (b) Call the zero-finding function, with the initial guess as the input argument, and the final answer and number of steps it took to find the final answer as the output arguments. (c) Print out the final answer and the number of steps it took to find the final answer in some self-explanatory format. Function M-file for finding a Zero (a) This function has one input argument, the initial guess for x. (b) This function has two output arguments, the final approximation of the xvalue at which the zero is found, and the number of steps it took to find it. (c) Set a convergence criterion of ε = 10−6 . (d) Initialize the number of iterations to zero. (e) Carry out the following steps until the absolute value of f(x) < ε where f is the function you are zeroing, and x is your current approximation of the zero. • Calculate an approximation to the derivative of the function at this point, from • Calculate a new approximation to the zero, from • Update the number of steps that you have taken through the loop. (f) Return to main Hint: Function Prototype function [x n] = findZero (initGuess) Function M-file f (a) This function has one input argument, x. (b) This function has one output argument, y. (c) The relation is Hint: Function Prototype function y = yValue (x)
Notes for submission: For this problem,You need only to submit your zero-finding function to the Sakai using attachment. Name you zero-finding function in the following matter.The format is important,if you did not follow this rule,your homework may not be able to be grated correctly or on time. sYourlD_hwk1_2.m Example s5073709022_hwk12.m
Notes for submission: For this problem, You need only to submit your zero-finding function to the Sakai using attachment. Name you zero-finding function in the following matter. The format is important, if you did not follow this rule, your homework may not be able to be grated correctly or on time. sYourID_hwk1_2.m Example : s5073709022_ hwk1_2.m