Write a function in Standard ML to calculate the Taylor expa

Write a function in Standard ML to calculate the Taylor expansion of the sin(x) function:

This is a programming assignment and not a math proof.

Question 2 Consider the Taylor expansion of the sin function (ar) you can see, it is also a sum of terms with a couple of twists. First, the signs alternate, second and the terms for even numbers are missing. The formula in sigma notation is (-1) 2.i-+1 (ar) sin (2.i+ 1) where the order-n summation contains the first n 1 terms of the expansion. Write a linear time ML function sinappx that, given a value n, computes in linear time in n, the Taylor expansion up to order n As you surely realized, computing (for instance) factorials from scratch for each term would not deliver the desired complexity. fun sinappx n x

Solution

function ans =finding(x,n)

y=zeros(1:n);

for i = 0:n

y(i) = (-1) ^ i * x^(2*i+1) / factorial(2*i+1);

end

ans =sum(y)

end

>> finding(x_value,y_value)

Write a function in Standard ML to calculate the Taylor expansion of the sin(x) function: This is a programming assignment and not a math proof. Question 2 Cons

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site