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 :
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 ..............
Get Answers For Free
Most questions answered within 1 hours.