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
Using MATLAB Write a user-defined MATLAB function for the following math function: y(x)= (-0.2x^3 + 7x^2)e^-0.3x...
Using MATLAB Write a user-defined MATLAB function for the following math function: y(x)= (-0.2x^3 + 7x^2)e^-0.3x The input to the function is x and the output is y. Write the function such that x can be a vector (use element-by-element operations). (a) Use the function to calculate y(-1.5) and y(5). (b) Use the function to make a plot of the function y(x) for -2 ≤ x ≤ 6.
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...
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x)...
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x) . exp(sin x), Using numerical integration method. When the user runs the script, he/she is prompted to input the lower and upper limits for numerical integration, both in radians, and your program outputs the integration result. You can use built-in trigonometric functions and the exponential function, but you are not allowed to use any built-in function to do the integration. You must use a...
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 :...
Let the function f be defined by y= f (x), where x and f (x) are...
Let the function f be defined by y= f (x), where x and f (x) are real numbers. Find f (2), f (-3), f (k), and f (k^2-1) f(x) = 2/3 x + 5
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