Question

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 loop for this problem.

Answer #1

**ANSWER :**

**MATLAB Script for function
"NumIntF":**

**function f =NumIntF(xi,xf)
h=0.001;
N=(xf-xi)/h;
ii=1;
while(ii<= (N+1))
if(ii==1);
x(ii)=xi;
y(ii)= cos(x(ii))*exp(sin(x(ii)))*h;
else
x(ii)=x(ii-1)+h;
y(ii)=y(ii-1)+cos(x(ii))*exp(sin(x(ii)))*h;
end
ii=ii+1;
end
f= y(N+1);
end**

**Results:**

**>> xi=0;
>> xf=3.14;
>> NumIntF(xi,xf)**

**ans =**

**0.0016**

**( PLEASE VOTE FOR THIS ANSWER )**

**I THINK IT WILL BE USEFULL TO YOU
..................**

**PLZZZZZZ COMMENT IF YOU HAVE ANY PROBLEM I WILL TRY TO
SOLVE IT ............**

**THANK YOU ..............**

1. Write a MATLAB script, by hand, on this page, that calculates
the nth degree Taylor expansion of cos x and then compares the plot
of this expansion to the original function. In one of your first
lines, you may fix n (e.g., n = 6) but the remainder of the code
should refer to n.

Write a MATLAB function
function [ AvgPos, AvgNeg ] = PosNegAverage ( X )
that calculates average of positive, AvgPos, and negative,
AvgNeg, elements of array X, using the for‐end loop and
if‐elseif‐else‐end selection structure. Do not use build‐in MATLAN
functions in calculations. Apply the developed function for the
following vector
X = [ ‐7, 1, 0, 0, 12, 6, 33.2, ‐7.5 ];

questions should be done on MATLAB
5) For the function f(x) = cos(x)exp(-x2) find and at 0.5 and =
1.

Write a Matlab script that plots the following functions over 0
≤ x ≤ 5π:
f1(x) = sin2 x − cos x,
f2(x) = −0.1 x 3 + 2 x 2 + 10,
f3(x) = e −x/π ,
f4(x) = sin(x) ln(x + 1).
The plots should be in four separate frames, but all four frames
should be in one figure window. To do this you can use the subplot
command to create 2 × 2 subfigures.

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.

Write a Matlab program to plot the cosine wave. That is plot
y=cos(k1x) vs. x for x varying from 0 to 2pi radians. The value of
k1 is given at the end of this document. You can choose the
increment for x. Note that large values of the increment will give
you a coarse graph. Note: Matlab has two functions to calculate the
sine of an angle: sin(x) and sind(x). What is the difference
between these two functions? Use help...

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...

Write a MATLAB program to determine the factorial value of an
input integer between 1 and 30. You may NOT use the built-in
factorial function. You must implement it using a for loop. Display
the result back to the user with 2 decimal places (yes, 2 decimal
places). The result should follow the following format:
The factorial value is *.xx

Write a MATLAB function and test bench script code to solve the
above simple RL/RC circuits by following the instructions noted
below. The input signal and impulse response generation should be
done in the function. The test bench script should be used only to
call the function and for signal plotting purposes. No plotting
should be done inside the function itself. Name your function
L2_C
Instructions: Input voltage ,x(t), can be AC or DC. Consider a
variable ‘w1’ which can...

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...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 2 minutes ago

asked 2 minutes ago

asked 2 minutes ago

asked 8 minutes ago

asked 9 minutes ago

asked 27 minutes ago

asked 42 minutes ago

asked 46 minutes ago

asked 46 minutes ago

asked 49 minutes ago

asked 54 minutes ago

asked 54 minutes ago