Question

What is the coding that I need to satisfy the questions and instructions. This is MATLAB...

What is the coding that I need to satisfy the questions and instructions. This is MATLAB

function project_2_mjh()

% PROJECT_2_ABC project_2_ABC() evaluates approximations of sin(x)

% using the Taylor series expansion.

%

% Name:

% Date:

% CMPSC 200

%

%

%

% Splash Screen

fprintf('Name: Muhaman Halawani\n');

fprintf('CMPSC 200\n');

fprintf('6 September 2018\n');

fprintf('\n')

% Description of the program

fprintf('');

fprintf('');

fprintf('\n')

% Have the user enter the angle

% Calculate the sine and the three Taylor series approximations

% Store each of these in their own variable

% Calculate the Percent Error of the four calculations

% Store each of these in their own variable

% Print the Results as a table using fprintf

% The first line is a reiteration of the input

% Line 2 is the actual value using the sine function and an error of 0

% Line 3 is the first approximation and its error and so on.

end

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

format long
function d = DtoR(degree)
d = degree*pi/180;
end
function fac = factor(n)
res = 1;
for i = 1:n
res = res * i;
end

fac = res;
end
function approx = Sine(val)
x = 0;
p = 2;
i = 1;
for k = 1:3
i = 2*k - 1;
x = x+ ( (-1)^p *(val)^i )/factor(i);
p = p + 1;
end
approx = x;
end
deg = input("Enter the value in degree: ");
radian = DtoR(deg);
approx =Sine(radian);
fprintf("Approximate value %.8f\n",approx);
trueValue = sin(radian);
erro = (trueValue - approx) * 100/ trueValue

=====================================================
See Output
1 format Long 2 function d - DtoR(degree) 3 d degree*pi/180; 4 en 5 function fac-factor(n) 6 res -1; 7 for i -1:n res = res * i; 9 end 10 11 fac - res; 12 end 13 function approx - Sine(val) 14 x=0; 15 p 2; 16 i- 1; 17 for k 1:3 18 1 = 2*k - 1; 19 x = x+ ( (-1)^p *(val) )/factor(i); 20 p p + 1; 21 end 22 approx - x; 23 end 24 deginput(Enter the value in degree: ; 25 radian= DtoR(deg); 26 approx -Sine(radian); 27 fprintf(Approximate value %. 8f\n , approx); 28 trueValuesin(radian); 29 erro - (trueValue approx) * 100/ trueValue CommandLine Arguments O Execute Save My Project Result. executed in 3.966 secs octave: X11 DISPLAY environment variable not set octave: disabling GUI features Enter the value in degree: 30 Approximate value 0.50000213 erro- -4.26517758500555e-04

Thanks, PLEASE UPVOTE if helpful

Add a comment
Know the answer?
Add Answer to:
What is the coding that I need to satisfy the questions and instructions. This is MATLAB...
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
  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • this is matlab coding I need to create histrogram plot of the model_year variable using 'bin...

    this is matlab coding I need to create histrogram plot of the model_year variable using 'bin size' can you help me create a histogram using bin size? A-load('Carbig.mat'); x=A.Displacement; y-A.Acceleration: fprintf('Min of displacement is fn'.min(x)); fprintf('Min of acceleration is fin'.min(y)) : fprintf('Max of displacement is %fn', max(x)); fprintf('Max of acceleration is fin',max(y)); fprintf('Mode of displacement is fWn', mode()); fprintf('Mode of acceleration is %fWn' mode(y)): fprintf('Mean of displacement is fWn'.mean()); fprintf('Mean of acceleration is fwn' mean(y)); subplot(2,1,1); scatter(y. A. Weight); xlabel('acceleration');...

  • This program has to be written in matlab 2. Write a function to find a root...

    This program has to be written in matlab 2. Write a function to find a root of f(c) using the secant method. Call this routine secant, call the file secant.m; its first line should be function [x,nf] = secant (fname, x0, x1, tol) fname is the name of the m-file which evaluates the function f(x), 20 and 21 are initial approximations to .c", and tol is a stopping tolerance. Your code should return an approximation x = 2X+1 to 3*...

  • I need not in pic or handwriting, in keyboard Spring 19 (1) ESC 152 Programming with...

    I need not in pic or handwriting, in keyboard Spring 19 (1) ESC 152 Programming with MATLAB Section 2 1) The Taylor series expansion for cos(x) is: coS(x). where x is in radians. Write a MATLAB program that determines cos (x) using the Taylor series expansion. The program asks the user to type a value for an angle in degrees. Then the program uses a loop for adding the terms of the Taylor series. If a is the nth term...

  • Instructions: Submit your script in a file named hwk08.m to the dropbox before 11:59 pm on the du...

    Instructions: Submit your script in a file named hwk08.m to the dropbox before 11:59 pm on the due date NOTE: This assignment is neither quick nor simple. You will be well served to start on it early, and to ask for help if you need it. Being a more substantial assignment than earlier hwk, it is worth- s. When you ask your calculator for the value of a function for a specified argument, (e.g., sin(22), cos(74), In(6.5)), it almost certainly...

  • Taylor series by Matlab Need Help with part b (a) Find the Taylor expansion of the...

    Taylor series by Matlab Need Help with part b (a) Find the Taylor expansion of the function squareroot x at x = 1 so that the associated Taylor polynomial has order n. (b). Let us denote the Taylor polynomial obtained in (a) as T_n(x). Using Matlab, compute the difference between two values T_n(1.1) and squareroot 1.1 for n = 0, 1, 2, 3, respectively. Collect the above values in a table. What is your observation of the difference in two...

  • There are also approximations of higher order derivatives that can be computed using only values ...

    Number 9 requires number 8 so please can you answer both? Thanks. Here's more context: There are also approximations of higher order derivatives that can be computed using only values of the original function. Consider the approximation: u(a + 2h)-2u(a + h) + u (a) h2 8. Using your knowledge of Taylor series, what derivative is approximated by Equa Many different combinations of terms can be used to create approximations to deriva- tion??? What is the order of the approximation?...

  • This is the given code: /** * This program uses a Taylor Series to compute a...

    This is the given code: /** * This program uses a Taylor Series to compute a value * of sine. * */ #include<stdlib.h> #include<stdio.h> #include<math.h> /** * A function to compute the factorial function, n!. */ long factorial(int n) { long result = 1, i; for(i=2; i<=n; i++) { result *= i; } return result; } int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "Usage: %s x n ", argv[0]); exit(1); } double x = atof(argv[1]); int...

  • (e) Consider the Runge-Kutta method in solving the following first order ODE: dy First, using Taylor series expansion, we have the following approximation of y evaluated at the time step n+1 as a...

    (e) Consider the Runge-Kutta method in solving the following first order ODE: dy First, using Taylor series expansion, we have the following approximation of y evaluated at the time step n+1 as a function of y at the time step n: where h is the size of the time step. The fourth order Runge-Kutta method assumes the following form where the following approximations can be made at various iterations: )sh+รู้: ,f(t.ta, ),. Note that the first term is evaluated at...

  • someone please do this corrcetly using matlab and following all instructions 1. (30 Points) It is...

    someone please do this corrcetly using matlab and following all instructions 1. (30 Points) It is known that the sine function can be expressed as: x(2k+1) sin(x) = (-1) +(2k + 1)! k=0 Truncate the series to compute the first seven estimates (ie, for k = 0,1,2,3,4,5, and 6) for x = You must use a for loop. All calculations and printing the table described below should be done from within the loop. For each estimate, determine the magnitude of...

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