[Date Index]
[Thread Index]
[Author Index]
Crash course in Mathematica syntax reqd
*To*: mathgroup at smc.vnet.net
*Subject*: [mg20251] Crash course in Mathematica syntax reqd
*From*: "Kai G. Gauer" <gauer at sk.sympatico.ca>
*Date*: Fri, 8 Oct 1999 18:30:23 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
All to be found in one input line (it should run in a similar coding
environment such as Fortran or C). For instance, we should actually be
inputting the a, b values after the program is "compiled" and then "run"
the main code from outside of the text editor as an executable (though
for this code it doesn't really matter so much). Yes, I've used Java and
Pascal before, but I've never really put Mathematica 3.0 to work as a
text editor for a programming language that, when compiled, would
execute as a C code, etc. I don't have any compilation devices at home
(except for Mathematica's capabilities) and I don't intend to spend
extra cash on a new compiler program yet. The prof says any high-level
language is acceptable to write this following bisection method of
e^(10(1-x))-1 = f[x] where |f|<1/10 in; I assume that Mathematica
fulfills his req's. I have to print the nth value and the value of f
after the nth iterate satisfying the above.
A few of my more prominent questions are: (i) Who has some better
documentation than the Mathematica handbook of writing compound
statements? Do I do as in other languages and write For
[i=1,i<5,{multiple amount of statements},i++];
etc..
(ii)
What is the equivalent of a Repeat {blah} Until {blahblah}; loop
(simplest Mathematica version please)? My personal favorite type of
loop!
(iii)
Where can I find some nice simple cut and paste loop button functions
(with the tab boxes) for general program writing? (two-fingered typist
syndrome)
(iv)
How do I best (or easiest) write the program first, then make it look
like it's compiled itself, then go outside of the In[1] statement and
ask for any old values? (as though the output didn't depend on the
input). I don't really want to use Eval[%,a->1,b->2] or similar. It
should be recognizable in almost any program language and yet run at the
same time.
(v)
what is the equivalent of variable type declaration, "double" in
Mathematica? I don't "want" Mathematica to calculate with 200 decimals;
the marker prefers to see the type of variable declared in advance. I
don't think he understands that N[%,8] is "equivalent" to double.
(** Please do nt submit a fully repaired solution if I'm going in a
completely wrong direction in terms of setting up the algorithm; I'm
only worried about the Mathematica syntax, etc, which seems to behave a
little bit more unusually than other languages. A crash course in
learning the Mathematica syntax, preferably before this weekend, would
be highly appreciable. You may assume that I've programmed in high-level
languages before, but never have formally used Mathematica as a
programing language in this sense. Most of my usage of Mathematica has
been for built-in function calculation such as plot for math. No, I'm
not asking you to do my HW either, as I don't lose marks for bad
Mathematica syntax! The output of this program is nothing for an outln
statement. p[1] gives1.05 after asking for it, but p2 won't iterate upto
a better value. Furthermore, While doesn't seem to want to hit its print
statement. Oh yeah, and n=100 is just a dummy value to keep the loop
going. I hope I've read the part on compound statements properly (ie)
when I can use ";" and when I can use ","....can I use {} also?
(a = 0.1;
b = 2;
For[n = 1, n < 100, p[n_] = a + (b - a)/2;
f[p[n] _] = E^(10(1 - p[n])) - 1;
While[Abs[f[p[n]]] >= 10^(-1),
Print[n, p[n]]
];
If[f[a] f[b] > 0,
a = p[n];
f[a] = f[p[n]]
];
If[f[a] f[b] <= 0, b = p[n]
],
(n++)
)
Prev by Date:
**Re: Locked In Block**
Next by Date:
**Re: Surface of Revolution**
Previous by thread:
**Re: Locked In Block**
Next by thread:
**Re: Crash course in Mathematica syntax reqd**
| |