Question

MATLAB write your own functions (5 of them) using for loop for a) 1/(1-x), b) e^x,...

MATLAB

write your own functions (5 of them) using for loop for

a) 1/(1-x),

b) e^x,

c) cos(x),

d) sin(x), and

e) ln(1+x)

do not use built-in factorial, or sine, cosine, log, and tangent functions.

Homework Answers

Answer #1

%%%question 1
% 1/(1-x) =1-x+x^2-x^3+x^4-x^5+......+(-x)^n +....infinite terms

function o=my_fun_question1(x)
o=0;
n=1000; %keep n very large
for i=0:n
o=o+(-x)^n;
end
end

%%%% question2
%% e^x= 1+x/1! +x^2/2!+ x^3/3!+....infinite terms

function o=my_fun_question2(x)
o=0;
n=1000; %keep n very large
prev_term=1;
o=prev_term;
for i=1:n
o=o+prev_term*(x/i);
prev_term=prev_term*(x/i);
end
end

%%%%%question 3
%%% cos x =1-x^2/2! +x^4/4! -x^6/6!+....
function o=my_fun_question3(x)
o=0;
n=1000; %keep n very large
prev_term=1;
o=prev_term;
for i=1:n
o=o+prev_term*((-1)^i )*(x*x/((2*i-1)*(2*i)));
prev_term=prev_term*(x*x/((2*i-1)*(2*i)));
end
end


%%%%%question 4
%%% sin x =x-x^3/3! +x^5/5! -x^7/7!+....
function o=my_fun_question4(x)
o=0;
n=1000; %keep n very large
prev_term=x;
o=prev_term;
for i=1:n
o=o+prev_term*((-1)^i )*(x*x/((2*i)*(2*i+1)));
prev_term=prev_term*(x*x/((2*i)*(2*i+1)));
end
end

%%%%%question 5
%%% ln 1+x = x-x^2/2 + x^3/3 +....
function o=my_fun_question5(x)
o=0;
n=1000; %keep n very large
for i=1:n
o=o+((-1)^(i+1))*(x^i)/i;
end
end

my_fun_question1(1/2)
my_fun_question2(1)
my_fun_question3(0)
my_fun_question4(0)
my_fun_question5(0)

Know the answer?
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
Similar Questions
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x)...
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...
Write a Matlab script that plots the following functions over 0 ≤ x ≤ 5π: f1(x)...
Write a Matlab script that plots the following functions over 0 ≤ x ≤ 5π: f1(x) = sin2 x − cos x, f2(x) = −0.1 x 3 + 2 x 2 + 10, f3(x) = e −x/π , f4(x) = sin(x) ln(x + 1). The plots should be in four separate frames, but all four frames should be in one figure window. To do this you can use the subplot command to create 2 × 2 subfigures.
Write a Matlab program to plot the cosine wave. That is plot y=cos(k1x) vs. x for...
Write a Matlab program to plot the cosine wave. That is plot y=cos(k1x) vs. x for x varying from 0 to 2pi radians. The value of k1 is given at the end of this document. You can choose the increment for x. Note that large values of the increment will give you a coarse graph. Note: Matlab has two functions to calculate the sine of an angle: sin(x) and sind(x). What is the difference between these two functions? Use help...
Write a MATLAB program to determine the factorial value of an input integer between 1 and...
Write a MATLAB program to determine the factorial value of an input integer between 1 and 30. You may NOT use the built-in factorial function. You must implement it using a for loop. Display the result back to the user with 2 decimal places (yes, 2 decimal places). The result should follow the following format:   The factorial value is *.xx
Find the derivatives of each of the following functions. DO NOT simplify your answers. (a) f(x)...
Find the derivatives of each of the following functions. DO NOT simplify your answers. (a) f(x) = 103x (3x5+ x − 1)4 (b) g(x) = ln(x3 + x) / x2 − 4 (c) h(x) = tan-1(xex) (d) k(x) = sin(x)cos(x)
Using for loop and if statement, write a MATLAB code to plot a graph for x(t)...
Using for loop and if statement, write a MATLAB code to plot a graph for x(t) as a function of time t in the range 0 to 12 in increment of 0.01 ?(?) = 1: 0 ≤ ? ≤ 1 2? − 1 1 ≤ ? ≤ 2 3 2 ≤ ? ≤ 3 −2.5? + 10.5 3 ≤ ? ≤ 5 −2 5 ≤ ? ≤ 6 4/3 ? − 10 6 ≤ ? ≤ 9 2 9 ≤...
1. Differentiate the following functions. Do not simplify. (a) f(x) = x^7 tan(x) (b) g(x) =...
1. Differentiate the following functions. Do not simplify. (a) f(x) = x^7 tan(x) (b) g(x) = sin(x) / 5x + ex (c) h(x) = (x^4 + 3x^2 - 6)^5 (d) i(x) = 4e^sin(9x) (e) j(x) = ln(x) / x5 (f) k(x) = ln(cot(x)) (g) L(x) = 4 csc^-1 (x2) (h) m(x) = sin(x) / cosh(x) (i) n(x) = 2 tanh^-1 (x4 + 1)
1a. Find the domain and range of the function. (Enter your answer using interval notation.) f(x)...
1a. Find the domain and range of the function. (Enter your answer using interval notation.) f(x) = −|x + 8|   domain= range= 1b.   Consider the following function. Find the composite functions f ∘ g and g ∘ f. Find the domain of each composite function. (Enter your domains using interval notation.) f(x) = x − 3 g(x) = x2 (f ∘ g)(x)= domain = (g ∘ f)(x) = domain are the two functions equal? y n 1c. Convert the radian...
3. Find the equation of the tangent line to the curve 2x^3 + y^2 = xy...
3. Find the equation of the tangent line to the curve 2x^3 + y^2 = xy at the point (−1, 1). 4. Use implicit differentiation to find y' for sin(xy^2 ) − x^3 = 4x + 2y. 5. Use logarithmic differentiation to find y' for y = e^4x cos(2x) / (x−1)^4 . 6. Show that d/dx (tan (x)) = sec^2 (x) using only your knowledge of the derivatives of sine/cosine with derivative rules. 7. Use implicit differentiation to show that...
Write a MATLAB function function [ AvgPos, AvgNeg ] = PosNegAverage ( X ) that calculates...
Write a MATLAB function function [ AvgPos, AvgNeg ] = PosNegAverage ( X ) that calculates average of positive, AvgPos, and negative, AvgNeg, elements of array X, using the for‐end loop and if‐elseif‐else‐end selection structure. Do not use build‐in MATLAN functions in calculations. Apply the developed function for the following vector X = [ ‐7, 1, 0, 0, 12, 6, 33.2, ‐7.5 ];