Question

4. Write the function ExpSeries that will take a real number x as input, and return the result of the following summation: rrin matlab please and do not use while or for ty for your time

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

Code:

x = 1; % you can choose any

%value you like for x

exp_apprx = ExpSeries(x)

exp_true_val = exp(x)

%Your Function

function exp_apprx = ExpSeries(x)

num = 0:9;

den = factorial(0:9);

term = (x.^num)./den;

exp_apprx = sum(term);

end

Output:

x = 1; % you can choose any %value you like for x exp_apprx = ExpSeries(x) exp_true_val = exp(x) exp_apprx 2.7183 exp_true_va

Add a comment
Know the answer?
Add Answer to:
in matlab please and do not use while or for ty for your time 4. Write...
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,...

  • An alternative way for calculating sin(x) is to use its Taylor series as the following: sinx)x-+...

    An alternative way for calculating sin(x) is to use its Taylor series as the following: sinx)x-+ Create a function named "sin_taylor" in MATLAB. This function takes two inputs. First input is the angle, and the second input determines the number of terms in Taylor series for approximation. Check the fidelity of your function by running sin-taylor( 7) and compare it with the exact value of it. Hint: “factorial" is a built-in function that you can use for calculating factorial of...

  • MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS....

    MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS. THE PROGRAM TO BE MODIFIED IS THE NEXT ONE: clc clear % Approximate the value of e ^ x using the Taylor Series x = input( 'Enter the value of x for e^x. x = ' ); t = input( 'Enter the amount of desired terms. t = ' ); i = 1; e_taylor = 0; % initializing the variable for the accumulator while...

  • 1) Write and test a well-commented Python function, called “myexp” that approximates the value for the...

    1) Write and test a well-commented Python function, called “myexp” that approximates the value for the function ?(?) = ? ? . This function can be approximated by a Taylor series ? ? ≈ ∑ ? ? ?! ∞ ?=0 , and recall that the factorial function is given by the recursive relationship ?! = ? (? − 1)!, ?ℎ??? ? ∈ ??? ≥ 0, ??? 0! = 1 1. You will need to write your own factorial function, and...

  • MATLAB Use the Taylor series cos(x)-1-to compute cos(x) to four decimal places (by comparing the value...

    MATLAB Use the Taylor series cos(x)-1-to compute cos(x) to four decimal places (by comparing the value with the matlab built-in function for cos). How many iterations does it take to get to 4- decimal place agreement? (hint: help factorial) 2! 4! 6!

  • write a Matlab program ( solve the three questions). please use array and create your own...

    write a Matlab program ( solve the three questions). please use array and create your own function to check primality Question 1 : [10 points) Write a MATLAB program that will store all the first 1000 prime numbers in an array variable named arr_of_primes. Please note that a prime number is a positive integer that is bigger than or equal to 2 which is divisible only by 1 and itself. Examples of the first 8 primes are: 2, 3, 5,...

  • THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

    THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...

  • Solve the following problem in MATLAB. Use format compact for all work to suppress extra lines....

    Solve the following problem in MATLAB. Use format compact for all work to suppress extra lines. Show all work and add comments as needed to explain your logic/steps. 1. The function f(x) = e* can be approximated by the following Taylor series: n=0 The first few terms of the Taylor series are: e 1 + x + + + + ...... 2! 3! 4! Keep in mind that the "!" symbol denotes factorial. For example, the factorial of 4 =...

  • MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a whi...

    MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function (do not use nextprime). MATLAB

  • photo of the code please and an explnation if possible, Construct a simple MATLAB function program...

    photo of the code please and an explnation if possible, Construct a simple MATLAB function program my_factorial which calculates product of first n positive integer numbers (i.e. find factorial n!). For full points: - Make sure you protect the code from illogical use (n must be positive integer) - Test the function by comparing with built in MATLAB function factorial(n) - Make sure you test your function for any limitations. O marks) -3. Using my factorial function from the previous...

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