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

  • Thread starter seto6
  • Start date
  • #1
251
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:

Answers and Replies

  • #2
114
1
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
 

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

  • Last Post
Replies
12
Views
1K
  • Last Post
Replies
5
Views
2K
Replies
0
Views
841
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
1
Views
1K
Replies
4
Views
2K
  • Last Post
Replies
3
Views
2K
Top