Question

Implement MATLAB code that calculates sin(x) using the following formula, and measure the absolute error from the MATLAB prov

0 0
Add a comment Improve this question Transcribed image text
Answer #1

x=3*pi;%change this as needed
k=50;%change this as needed
%assuming k is the number of terms

exact=sin(x);
sinx=zeros(1,k);
sinx(1)=x;%store approximation for every value of k from 1 to 50
for i=2:k
sinx(i)=sinx(i-1)+(x)^(2*i-1)*(-1)^(i+1)/factorial(2*i-1);
end
err=abs(sinx-exact);
plot(1:k,sinx,'ro',1:k,err,'b')
legend('approximation','absolute error')
grid on

x=3*pi;%change this as needed k=50;%change this as needed %assuming k is the number of terms CON 1000 o approximation - absol

Add a comment
Know the answer?
Add Answer to:
Implement MATLAB code that calculates sin(x) using the following formula, and measure the absolute error from...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use MATLAB and PLZ comment the code so that it is easy to understand Implement the...

    use MATLAB and PLZ comment the code so that it is easy to understand Implement the following series of sinusoidal signals in MATLAB: 1 sin(kt) where N 30 k=1 x(t) k 1 Write a MATLAB script which does the following steps First define and plot signal sin(t) for 0 St s 3Twhere T is the fundamental period of this signal The signal you just implemented is x(t) with N 1 a. Then modify your code to be able to define...

  • Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func:...

    Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func: the function/equation that you are required to integrate -a, b: the integration limits n: the number of points to be used for the integration I:Integral estimate a) Write a function capable of performing numerical integration of h(x) using the composite trapezoidal rule. Use your function to integration the equation with 9 points. Write a function capable of performing numerical integration of h(x) using the...

  • MATLAB %% T = 1; N = 11; np = 2; dt = 0.001; tmax =...

    MATLAB %% T = 1; N = 11; np = 2; dt = 0.001; tmax = np*T; t = -tmax:dt:tmax; %% Function 1 %the following code was used to create the x(t) function xrange = floor((T/dt)/15); x1 = linspace(0,1,xrange); x2 = x1(end-1:-1:1); x3 = linspace(0,2,2*xrange); x4 = x3(end-1:-1:1); x5 = zeros(1,xrange); x6 = x1; x7 = 2*ones(1,xrange); x8 = 1+x2; x9 = -0.5*ones(1,xrange); x10 = x1/2-0.5; xtemp = [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10]; ztemp =...

  • CONVERT THE FOLLOWING MATLAB CODE FROM SOURCE PANEL METHOD TO VORTEX PANEL METHOD: clc;clear all;...

    CONVERT THE FOLLOWING MATLAB CODE FROM SOURCE PANEL METHOD TO VORTEX PANEL METHOD: clc;clear all;close all; Vinf=100; % freestream velocity R=1; % cylinder radius n=4; % number of panels alpha=2; % angle of attack dtheta=2*pi/n; theta=pi+pi/n:-dtheta:-pi+pi/n; X=R*cos(theta); Y=R*sin(theta); for i=1:n % angle of flow with tangent of panel phi(i)=-alpha+atan2((Y(i+1)-Y(i)),(X(i+1)-X(i))); % angle of flow with normal of panel beta(i)=phi(i)+pi/2; x_mid(i)=(X(i+1)+X(i))/2; y_mid(i)=(Y(i+1)+Y(i))/2; S(i)=sqrt((Y(i+1)-Y(i))^2+(X(i+1)-X(i))^2); end % Source Panel Method for j=1:n neighbors(:,j)=[1:j-1 j+1:n]; xi=x_mid(j); yi=y_mid(j); for i=1:n-1 m=neighbors(i,j); Xj=X(m); Yj=Y(m); Xj1=X(m+1); Yj1=Y(m+1); A=-(xi-Xj)*cos(phi(m))-(yi-Yj)*sin(phi(m));...

  • Implement the following equation using matlab code N-1 1 Em N x(mN) i-0 N-1 1 Em N x(mN) i-0

    Implement the following equation using matlab code N-1 1 Em N x(mN) i-0 N-1 1 Em N x(mN) i-0

  • Using matlab, write the code and plot the graph for the following equations. The x axis...

    Using matlab, write the code and plot the graph for the following equations. The x axis would be theta from 0 deg to 360 deg while the y axis would be angular or tangential position, velocity and acceleration. 10 100 E7360 AB- eD100mm sin 1O-Sn 2To ne cose, t Cas 2 3 4 O,= To (reano,re bease-feo, sene-Feo 6 as ) Cos O2 10 100 E7360 AB- eD100mm sin 1O-Sn 2To ne cose, t Cas 2 3 4 O,= To...

  • Please solve using matlab and post the code used 1) Consider the following input data: x...

    Please solve using matlab and post the code used 1) Consider the following input data: x = [O 3.6 10 12 16.4 18.4 24]; y = [52 32.830 6.670 7 5.030 2*pi 8]; Use polyfit to a) determine the best polynomial fit for desired order n (1, 2, 3, 4, 5) b) determine the error between fitted and experimental data for the values of x c) determine the time to compute order range 0 to 6 using tic toc d)...

  • Using MATLAB, duplicate to the two graphs shown in the figure below Requirements 1. Show the MATLAB code used to plot both functions 5cos (nt-ng) (V) 5 e-"X cos (2nft-2nx/A) (V) a. y b- Use the f...

    Using MATLAB, duplicate to the two graphs shown in the figure below Requirements 1. Show the MATLAB code used to plot both functions 5cos (nt-ng) (V) 5 e-"X cos (2nft-2nx/A) (V) a. y b- Use the frequency, wavelength and attenuation shown in the figure below when plotting graph (b) 2. 3. 4. Place labels for the x and y axis showing appropriate units Extend the x-axis to 10 cm and use a sampling rate of 0.1 mm Submit the final...

  • Create a Matlab code using ode45 function to solve the following two equations of a pendulum: m+M)x'' - ml'' cos + ml'' sin = F -x'' cos + l'' - g sin = 0 Force...

    Create a Matlab code using ode45 function to solve the following two equations of a pendulum: m+M)x'' - ml'' cos + ml'' sin = F -x'' cos + l'' - g sin = 0 Force = 10N 5kg pendulum initial angle = 30 We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe...

  • I need the Matlab code please. Problem Statement #2: ds (c) using the To the same...

    I need the Matlab code please. Problem Statement #2: ds (c) using the To the same initial guesses as in (b). 5.9) The saturation concentration of dissolved oxygen in freshwater can be calculated with the equation 1.575701 x 105 In of =-139.3441144 20 34411 + - Ta where mum const! of the 1.243800 x 100 6.642308 x 107 1 = 1 72 8.621949 x 1011 Deva ks = 5.12 car where Oxf = the saturation concentration of dissolved oxy- gen...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT