1) The anonymous function allows us to easily create mathematical functions, and
ID: 3567083 • Letter: 1
Question
1) The anonymous function allows us to easily create mathematical functions, and store them in variables. The documentation below provides additional details http://www.mathworks.com/help/matlab/matlab prog/anonymous-functions.html For example, let's say we wanted to implement the equationx2+2x +1. We could use an anonymous function to create a new function and store in in f. f@(x) xA2 +2"x+ 1 Now, we can say f(3), and it will evaluate the function at 3 (plugging in 3 for all x). a) Write the MATLAB code to create the function x21, and evaluate that function at x -5. b) Write the MATLAB code to loop from 1 to 5, and evaluate the function from part a at each iteration (the first iteration will be 1), second f(2), etc.). You can use the looping variable as an argument to be passed to f. 2) Often times, loops are not as simple as the following code: [ for i [15] Consider the following example, we have three variables: a lower bound (a), an upper bound (b), and a step size (dx). If we wanted to loop from a' to b' by step size dx, we would write the following: for i a.dx.b; Using the same variables, answer the following questions. a) Write the MATLAB code to loop from a, by step size dx, to one step before b (also known as b - dx). Use the variable j as your looping variable, as was done in the above examples a) Write the MATLAB code to loop through all of the midpoints. Things to consider include: The step size is still dx. In other words, the distance between each midpoint is dx. - -The first midpoint is located between aand (a+ dx). The final midpoint is located between b and (b - dx).Explanation / Answer
100% Fresh answer, guaranteed to get you best grades possible. Just check it out: http://programmingtutor3.tk/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.