Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

why matlab returns Inf value

Status
Not open for further replies.

rameshrai

Full Member level 3
Joined
Aug 16, 2010
Messages
158
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,298
Activity points
2,272
hi,

I have a problem in matlab, the following returns Inf, does anybody know why this is so and how I can truncate the value so that 2^ans is not Inf

V =

39.139000142183406

>> 2^ans

ans =

Inf

thanks
 

The MATLAB software creates the ans variable automatically when you specify no output argument.
When you type "V", Matlab gives its value but the ans variable is not updated. It preserves its previous value, that must have been big enough that 2^ans overflows.
Regards

Z
 

zorro is correct. The value you assign to V is not automatically assigned to the "ans" variable. You are seeing Inf because the value of "ans" is a large number left over from something you were doing before. You can check the value of ans by just typing "ans".

Try the following code instead:
Code:
format long g;
V = 39.139000142183406;
W = 2^V

W =

          605359055128.849
This assigns the result to the variable "W", so ans is not affected.

Alternatively, if we write:
Code:
format long g;
V = 39.139000142183406;
2^V

ans =

          605359055128.849
then "ans" is assigned because we didn't explicitly state a variable to assign to.
 
no this was just for example, I get Inf while running a program.

how do I truncate accuracy in matlab? I think this is due to precision value setting of matlab
 

no this was just for example, I get Inf while running a program.
As pointed out, the example is meaningless. We still don't know which of your calculations gets inf result.

Unless otherwise specified, Matlab uses double precision format. So 2^n will overflow to inf for n > 1023.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top