Question
can someone provide how i code this with matlab and provide explanations for each of them?
The natural logarithm of 1+x can be expressed using the Mercator series, given on the right-hand side of the equation below:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The problem is solved using MATLAB. The random number is generated using 'rand' function and a for loop is used to compute the sum of the first 100 terms. If you see the right hand side terms, the sign of each term alternates from plus to minus. If the power of x is odd, then the sign is plus and if the power of x is even, then the sign is minus.

The MATLAB code is as follows. Each command has comments

-------------- START OF MATLAB CODE -------------

%=========================================
% Mercator series
%=========================================
% The series is natural logrithm
% ln(1+x) = x - x^2/2 + x^3/3 - x^4 + .....
% We need to generate the sum for the first
% 100 terms

% (a) Generation of a random number between (-1.0 to 1.0)
% The rand function generates a real random value between (0.0 to 1.0)
% We need to make adjustments to match our requirements
% x = xmin + xrange*rand(1,1)
xmin = -1; % Minimum value in our requirement
xrange = 2; % Range of x in our requirement
x = xmin + xrange*rand(1,1); % A real random number is generated

% (b) Computation of mercator series
% Let y be the variable used for computation and representation of
% natural logarithm of (1+x)
% Number of terms is 100
N = 100; % Number of terms
y = 0; % Initial value
% Place a for loop for computation
for i=1:N
   % The power of x is odd put addition sign else subtraction sign
   if mod(i,2) ~= 0
       y = y + x^i/i;
   else
       y = y - x^i/i;
   end
end

% Display the generated random number
disp(x)
% Display the result of mercator series
disp(y)

%=========================================
% Verification of Mercator series
%=========================================
% Displaying the natural logarithm of x
disp(log(1+x))

------------- END OF MATLAB CODE --------------------

Save the above MATLAB code as 'mercator.m' file and run the file in the command window of MATLAB as 'mercator'. The results is displayed in the command window. The results which are displayed are

the first line is 'x', the second line is 'sum of terms' and the third line is 'natural logarithm'

Sample results are shown below after running the file in MATLAB command window,

0.66284
0.50852
0.50852

---------------------

0.58989
0.46366
0.46366

---------------

-0.85914
-1.9600
-1.9600

--------------

-0.45270
-0.60276
-0.60276

====================================================

Add a comment
Know the answer?
Add Answer to:
Can someone provide how i code this with matlab and provide explanations for each of them?
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
  • 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...

  • Please provide Matlab code. Components are inconsistencies all components designed to perform at a nominal value,...

    Please provide Matlab code. Components are inconsistencies all components designed to perform at a nominal value, however, due to manufacturing subject to variation from its desired value. are Referring to the diagram above, consider the following: Voltage is specified to be 18 V, tolerance is + 0.5 V Resistors Ri and R2 is specified to be 10 and R3 is specified to be 20 The tolerance on Ri and R2 is + 0.5 (+5 % of nominal) The tolerance on...

  • Please can you solve it using MATLAB. (1) Generate random signals [n] and hn, each of...

    Please can you solve it using MATLAB. (1) Generate random signals [n] and hn, each of length N, and measure the time it takes to compute the linear convolution of r[n using the linear convolution definition and using the FFT method . Plot a graph of the results for N 104 to 10 in steps of 10. (2) Consider the signal x[n]-cos(0.3n),。£11S 100. Generate a plot of: ·The magnitude and phase of the DTFT of x[n] for 0 2π The...

  • In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename...

    In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename myrowproduct (A,x) Undefined function or variable 'Filename' Did you mean: mfilename : myrowproduct (A, x) Undefined function or variable 'myrowproduct' function y = myrowproduct(A,x); function y my rowp roduct (A, x); Error: Function definition not supported in this context. Create functions in code file. (, 2,,)T 4. The product y Ax of an m x n matrix A times a vector x= can...

  • Matlab code assistance - task 1 and 6 I think I am right and just need...

    Matlab code assistance - task 1 and 6 I think I am right and just need to be pointed in the right direction if I should change anything %% Task 1 % create the 3 row vectors shown in Ex 8 using 3 different approaches Ex 8 = using the colon operator and also the linspace function, create the following row vectors -5 -4 -3 -2 -1 5 7 9 8 6 4 % 1. list the values explicitly (square...

  • This is a matlab HW that I need the code for, if someone could help me figure this out it would b...

    This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...

  • can you answer both #1 (a&B) and #2 please 1. Write MATLAB code to do the...

    can you answer both #1 (a&B) and #2 please 1. Write MATLAB code to do the following: (4 pts) a) Find the area of the circles where r=[7, 8, 10] using A = tr2 b) Find the distance traveled by a ball falling in the air is given by the equation x=x0+vot+ at?. Calculate the position of the ball at time t = 5s, XO = 10m, vo= 15 m/s, and a = 9.81 m/sec^2. Write MATLAB code to accomplish...

  • roblem 5: When can we neglect axial conduction? Consider steady, fully developed, laminar flow inside a...

    roblem 5: When can we neglect axial conduction? Consider steady, fully developed, laminar flow inside a round tube, with the energy equation: The two terms on the right hand side represent conduction effects in the radial and axial directions, respectively. In convection analysis we usually neglect the axial conduction term, resulting in Eq. 8.48. Let's investigate the suitability of this approximation, by comparing the relative magnitudes of those two terms for a tube flow with constant wall temperature The full...

  • I need help integrating to find the PDF CDF in MATLAB. (a) 1. Generate six sequences of uniform random variables (length 10,000) in the range [-0.5,0.5]. Each element in the ith sequence can be consi...

    I need help integrating to find the PDF CDF in MATLAB. (a) 1. Generate six sequences of uniform random variables (length 10,000) in the range [-0.5,0.5]. Each element in the ith sequence can be considered to be one realization of the random variable X, for i- 1,2,..., 6. Note that these six uniform random variables are independent and identically distributed. Com- pute new random variables as follows: 6 i-1 This results in two new sequences, the elements of which can...

  • (1 point) Frobenius' method: finding solutions as generalized power series Example: Consider the equation Tºg +...

    (1 point) Frobenius' method: finding solutions as generalized power series Example: Consider the equation Tºg + Tự+(x - 3) = 0. Dividing by r, the equation becomes y' + (1/2y + (1/x - 3/x)y = 0. Sincer(1/) = 1 and .ca(1/x - 3/) = x - 3 are both analytic, x = 0 is a regular singular point, so we can solve the equation by generalized power series around x = 0. Let y(x) = Cox® + C1.+1 + c2r4+2...

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