Question

Write a user-defined function, in MATLAB, with function call val=evalf(f,a,b) where f is an inline function,...

Write a user-defined function, in MATLAB, with function call val=evalf(f,a,b) where f is an inline function, and a and b are constants such that a<b. The function calculates the midpoint m of the interval [a,b] and returns the value of (1/2)f(a)+(1/3)f(m)+(1/4)f(b). Execute the function for f(x)=e^(-x)*cos(2x), a=-1, b=3.

Homework Answers

Answer #1

//Screenshot of the code:

//evalf.m

//main.m

//Sample Output:

//Code to copy:

//evalf.m

%Define a function evalf to evaluate the function f(x) = %e^(-x)*xos(2*x).

function value = evalf(f,a,b)

%Find the mid point of the a and b.

m = (a+b)/2;

%Calculate the value of the variable val. Function f is an %inline function and replace f(a), f(b), and f(m) with the %expression exp(-a)*cos(2*a), exp(-b)*cos(2*b), and %exp(-%mid)*cos(2*m).

value = (1/2).*f(a)+(1/3).*f(m)+(1/4).*f(b);

%End the function.

end

//main.m

%Make a function f(x) = e^-x*cos(2*x) inline.

f =inline('exp(-x).*cos(2*x)');

%Call the function evalf and pass the inline function, -1, %and 3 as arguments.

val = evalf(f,-1,3)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method...
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method (use the form of second-order Runge-Kutta method, Eqs(10.65),(10.66)). For function name and arguments use [x,y]=odeMIDPOINT(ODE,a,b,h,yINI). The input argument ODE is a name for the function that calculates dy/dx. It is a dummy name for the function that is imported into odeMIDPOINT. The arguments a and b define the domain of the solution, h is step size; yINI is initial value. The output arguments, x...
Let f be the function defined by f(x)=cx−5x^2/2x^2+ax+b, where a, b, and c are constants. The...
Let f be the function defined by f(x)=cx−5x^2/2x^2+ax+b, where a, b, and c are constants. The graph of f has a vertical asymptote at x=1, and f has a removable discontinuity at x=−2. (a) Show that a=2 and b=−4. (b) Find the value of c. Justify your answer. (c) To make f continuous at x=−2, f(−2) should be defined as what value? Justify your answer. (d) Write an equation for the horizontal asymptote to the graph of f. Show the...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
MATLAB 2017b Write a program which will: Accept three numbers from the user: a, b and...
MATLAB 2017b Write a program which will: Accept three numbers from the user: a, b and c which can assume any value. Accept Dx and Dy for the calculations of the function Write a function which accept a, b, c, Dx and Dy and will draw the following surface Where x and y vary in the range of -10?x?10 -10?y?10. Allow the user to rerun the program and exit the program upon request.
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that implements the bisection method. You function should take as input 4 arguments with the last argument being optional, i.e, if the user does not provide the accuracy tol use a default of 1.0e-6 (use varargin to attain this). Your function should output the approximate root, approx_root and the number of iterations it took to attain the root, num_its. However, if the user calls the...
1. A function f : Z → Z is defined by f(n) = 3n − 9....
1. A function f : Z → Z is defined by f(n) = 3n − 9. (a) Determine f(C), where C is the set of odd integers. (b) Determine f^−1 (D), where D = {6k : k ∈ Z}. 2. Two functions f : Z → Z and g : Z → Z are defined by f(n) = 2n^ 2+1 and g(n) = 1 − 2n. Find a formula for the function f ◦ g. 3. A function f :...
**C code only In this part, you will write a simple user-defined function that prints a...
**C code only In this part, you will write a simple user-defined function that prints a message. This function does not require any parameters or return value. The purpose is simply to get you started writing functions.Open repl project Lab: User-Defined Functions 1. Write a program that calls a function. This function should do the following: 1.Ask the user their name 2. Print a "hello" message that includes the user's name Example output: Please enter your name: ​Mat Hello, Mat!...
1. Find the constants a and b so that the function f is continuous, where f(x)...
1. Find the constants a and b so that the function f is continuous, where f(x) =(ax^2 + bx if x <=1 or x > 2; (7x+4) 3 if 1 < x <= 2
Which functions fit the description? function 1: f(x)=x^2 + 12. function 2: f(x)= −e^x^2 - 1....
Which functions fit the description? function 1: f(x)=x^2 + 12. function 2: f(x)= −e^x^2 - 1. function 3: f(x)= e^3x function 4: f(x)=x^5 -2x^3 -1 a. this function defined over all realnumbers has 3 inflection points b. this function has no global minimum on the interval (0,1) c. this function defined over all real numbers has a global min but no global max d. this function defined over all real numbers is non-decreasing everywhere e. this function (defined over all...
The function f(x) = 3x 4 − 4x 3 + 12 is defined for all real...
The function f(x) = 3x 4 − 4x 3 + 12 is defined for all real numbers. Where is the function f(x) decreasing? (a) (1,∞) (b) (−∞, 1) (c) (0, 1) (d) Everywhere (e) Nowhere