Calculating e, using matlab (how to get answer in double type)

  • Thread starter Thread starter seto6
  • Start date Start date
  • Tags Tags
    Matlab Type
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
seto6
Messages
248
Reaction score
0

Homework Statement



ok i am using Euler's way, i have to calculate "e"=2.718281828.

my script(see below) works but it only prints up to 4 decimal places, i have no idea why, help me please, thank you in advance.

Homework Equations



N/A

The Attempt at a Solution



Code:
function [eis] = euler1(in)
c=in-1;

while c>=1,
    
    if c == double(in-1),
        Q = double(c+(c/in));
    end
    
    Q= double(c + (c/Q));
    
    alpha = double(Q);
    c=c-1;
end
eis = 2+ 1/(double(alpha));
 
Last edited:
Physics news on Phys.org
There's several ways to do this. The easy way is to just change the way strings are formatted.

>> help format

For more precision, try

>> help fprintf