Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Increasing calculation precision

Subject: Increasing calculation precision

From: Marty McFly

Date: 23 May, 2013 08:56:08

Message: 1 of 2

Hi,

I have a simple question.

When I want to make a simple calculation consisting too big numbers and correspondingly small numbers, I can't get the precise result. For example:

"7e9 - 2e3"

yields 7e9 in Matlab, which is not the expected result.

Maybe it calculates it correctly bu doesn't display the precise answer.

How can i make Matlab to show me the exact result?

Thanks.

Subject: Increasing calculation precision

From: dpb

Date: 23 May, 2013 13:28:01

Message: 2 of 2

On 5/23/2013 3:56 AM, Marty McFly wrote:
> Hi,
>
> I have a simple question.
>
> When I want to make a simple calculation consisting too big numbers and
> correspondingly small numbers, I can't get the precise result. For example:
>
> "7e9 - 2e3"
>
> yields 7e9 in Matlab, which is not the expected result.
>
> Maybe it calculates it correctly bu doesn't display the precise answer.
>
> How can i make Matlab to show me the exact result?

 >> 7e9-2e3
ans =
    7.0000e+09
 >> format long
 >> 7e9-2e3
ans =
      6.999998000000000e+09
 >>

doc format

Of course, a double has roughly 15 decimal digits of precision; if your
ranges are beyond that loss of some precision is inevitable w/o some
other machinations. But, for most things, default double is generally
all one needs.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us