Professional Documents
Culture Documents
Q1: Part (C) Code:: Function
Q1: Part (C) Code:: Function
Code:
% 1 (c)
syms x
%% function f(x) = arctan(x)
f_x = atan(x);
%% Maclaurin expension of arctan(x) for 9th order
T=taylor(f_x, x, 'Order', 9);
%% Integration of |f(x) T^9| at range [-1 1]
Code:
function [N1, N2] = HW2_2a_20209999(T)
e = exp(1);
%% For N1
% initial staring point k=0
N1 = 0;
approximation1 = 1;
error1 = abs(e - approximation1);
% Untile the condition is satisfied, N1 grows up 1 by 1
while error1>T(1)
N1 = N1 + 1;
approximation1 = approximation1+ 1/factorial(N1);
% use the command "factorial(n)" to compute the n!
error1 = abs(e - approximation1);
end
%% For N2
% initial staring point k=0
N2 = 0;
approximation2 = (1 + 1/N2)^N2;
error2 = abs(e - approximation2);
% Untile the condition is satisfied, N2 grows up 1 by 1
while error2>T(2)
N2 = N2 + 1;
approximation2 = (1 + 1/N2)^N2;
error2 = abs(e - approximation2);
end
end
%------------------------------
demo2a.m:
This one is the main function form where i have called the function
HW2_2a_20209999 of question Q2(a)
Code:
Q2 part (c)
Function code:
end
%-------------------------------------------------
clear all
A = [1 2 3;4 5 6;7 9 9]
[D] = HW2_2c_20209999(A)