Message Boards Message Boards

0
|
1671 Views
|
16 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Decimal format in Numberform usage

Posted 11 months ago
16 Replies
Posted 11 months ago
Posted 11 months ago

Issue 1: The numbering in the workbook is not sequential now. I had not been paying attention, but does re-evaluating an input screw up the numbering?

If you're referring to the In[] and Out[] labels, yes. Those labels show you the order in which cells were evaluated, not the order in which they appear in the notebook. If you were to evaluate one cell 10 times in a row, then that cell's label would be incremented 10 times.

POSTED BY: Eric Rimbey
Posted 11 months ago

Issue 3: I could not set the current working directory. See in -out(134,135, 136). The directory "D:\temp" is valid. I thought my SetDirectory syntax was correct. It didn't work. What am I missing in the syntax? what is wrong with In(135)?

Looks to me like you need to escape the \. If you look at the message, it looks like the \t was interpreted as a tab. You probably need something like "D:\temp". You can also use FileNameJoin to avoid dealing with system-dependent delimiters.

POSTED BY: Eric Rimbey
Posted 11 months ago
POSTED BY: Eric Rimbey
Posted 11 months ago
POSTED BY: Eric Rimbey
Posted 11 months ago

Thanks for the quick and clear responses. I think I have 3 of 4 items down OK. As far as directory set, I figured out that I need to use forward slash(/) in path definitions and not the backslash(), which gets interpreted as an ESC as you noted. In my case "D:/temp" works as input to Mathematica, while the std windows form is "D:\temp. I notice that the echoed return value is the std windows form.

I tried the transpose form you suggested, but it didn't work for me. See attached jpg of program and resulting csv output.

I set up a two-row numeric matrix with m1 = {{1, 2, 3}, {4, 5, 6}}.

Then using Export["test_num2.csv", m1], created the following: 1,2,3 4,5,6 as expected. Using Export["test_num2T.csv", Transpose[m1]] results in a file with 1,4 2,5 3,6 This is good. What I don't know how to do is to have a variable 'forget' its history. I tried a simple example: q=Pi qn=N[q,10] I expect qn to be a 10 decimal approximation to pi, a finite decimal and nothing more. Evaluating N[qn,10] and N[qn,20] give identical 10-digit results. qn is no longer pi, but a finite approx.Yeah! However, in the attached example, the line xn = N[Column[x/50], 20] does not seem to create a set of specific approximate decimal numbers, but seems to maintain its embedded history. How to fix so that the exported entries are as displayed in xn?

Lou

Attachment

POSTED BY: Louis Poulo
Posted 11 months ago

I'm not quite following your question. But it looks to me like you still have that Column in there somewhere.

POSTED BY: Eric Rimbey
Posted 11 months ago

So, just don't do this:

xn = N[Column[x/50], 20]

There's no reason to set a variable to a Column expression. I mean, I suppose there could be a case where you're building up a visual display and so you want to have a variable to represent part of that display so you can refer to it, but to me it looks like you're trying to compute some data, and in that case the Column is just going to make life difficult.

If you like looking at your data at certain points during the calculation, then do this:

xn = N[x/50, 20];
Column[xn]

Your variable xn will be set to something useful, and you'll have a nice display of it to look at.

POSTED BY: Eric Rimbey
Posted 11 months ago

I'm really not grokking the rest of your question, but here are some ways to "forget" a variable's value (variables don't remember any history).

x =. (* This removes the value associated to x. *)
Clear[x] (* This also removes values associated to x. *)
ClearAll[x] (* This removes values and attributes and some other things, basically makes it as if x never existed before now. *)
Remove[x] (* This removes x entirely from the environment. *)

You could also just set x to another value, whatever new value you want it to have.

POSTED BY: Eric Rimbey
Posted 11 months ago

It might be better at this point to add a new question. By starting fresh you can isolate your new question, and then maybe folks can understand better what you're asking.

POSTED BY: Eric Rimbey

Please use one of the methods explained here http://wolfr.am/READ-1ST to include your formatted code or notebook. Thank you.

POSTED BY: Moderation Team
Posted 11 months ago

Since you're new to Mathematica, I'm going to be presumptuous and provide some guidance that you didn't ask for about something that commonly trips up newcomers.

Understand that NumberForm is just a special wrapper. Evaluate this:

NumberForm[1`20, 20]

The result will look something like this: 1.0000000000000000000. But if you look at the actual structure of the result by evaluating FullForm,

FullForm[NumberForm[1`20, 20]]

you'll see that it's

NumberForm[1.`20., 20]

NumberForm, and all of the related *Form functions are just wrappers that tell the front end how to display something. This can cause problems if you subsequently want to do calculations:

NumberForm[1`20, 20] + 1

The result displays as 1+1.0000000000000000000, because the evaluator doesn't know how to do arithmetic with NumberForm expressions, and the evaluator is looking at

Plus[1, NumberForm[1.`20., 20]]
POSTED BY: Eric Rimbey
Posted 11 months ago

Glad to have you jump in. I gather that all of the display commands should be the last things(outermost in syntax) executed, since I assume they do just that - only affect the display, and can't calculate as you point out.

POSTED BY: Louis Poulo

There are many intricacies with the usage of NumberForm and of N. According to documentation,

NumberForm works on integers as well as approximate real numbers.

The number 1/50 is neither integer nor approximate real. You must first convert it to approximate with N. Also, you cannot apply NumberForm to a whole column, but only to single numbers:

Column[Map[NumberForm[N[#, 20], 20] &, {1, 2, 4, 6, 7, 49.999999}/50]]
POSTED BY: Gianluca Gorni
Posted 11 months ago

I haven't tried your composite line as yet; presumably it will give the column I'm looking for. I'll study help on and parse the sequence of commands in this. I haven't seen Map as yet; so a lot to learn.

Thx

POSTED BY: Louis Poulo

This version may be easier to parse:

Column[{1, 2, 4, 6, 7, 49.999999}/50]
N[%, 30]
NumberForm[%, 20]

First you see the numbers as you typed them. Then you see what happens by calculating all exact numbers with 30 digits of precision but default display. Last we see all numbers that have at least 20 digits of precition displayed with 20 digits.

The matter is complicated. Don't get discouraged if you feel confused at the start.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract