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

  • Thread starter Thread starter seto6
  • Start date Start date
  • Tags Tags
    Matlab Type
AI Thread Summary
The discussion centers on calculating the mathematical constant "e" using Euler's method in MATLAB, with a focus on output precision. The user’s script successfully computes "e" but only displays results up to four decimal places. Suggestions include modifying string formatting and utilizing the `fprintf` function for increased precision in output. The conversation highlights the importance of adjusting display settings in MATLAB to achieve the desired numerical representation. Overall, enhancing the script's formatting can resolve the precision issue.
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
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Replies
1
Views
268
Replies
1
Views
1K
Replies
1
Views
2K
Replies
10
Views
2K
Replies
10
Views
2K
Replies
3
Views
2K
Replies
1
Views
2K
Back
Top