A55
==
NDSolve seems to have difficulties with solving
integral equation.> n = 5; NDSolve[{D[[Sigma]norm[z, t],
t] == 3*z*Integrate[[Sigma]norm[z,> t]^n*z, {z, 0, 1}] -
[Sigma]norm[z, t]^n,> [Sigma]norm[z, 0] == 1.5*z,
[Sigma]norm[0, t] == 0}*[Sigma]norm[z,> t], {z, 0.01,
1}, {t, 0.01, 2}]> Mathematica returns a message>
NDSolve::deql: The first argument must have both an
equation and an > initial condition.> which I cannot
understand.> Can anybody tell what's wrong with my attempt?>
> -Toshi> I am not really sure that your question isn't a
joke.NDSolve solves differential equations, not integral
equations.Although there are relations between these topics,
they are certainlynot the same.Alois-- Vienna University
of Technology,
====
evaluating the following gives you a
sample x=x+1 button:NotebookPut@Notebook[{Cell[BoxData[
ButtonBox[(x = (x + 1)), RuleDelayed[ButtonFunction,
CompoundExpression[If[Not[ ValueQ[x]], Set[x, 0]], Set[x,
Plus[x, 1]]]], Rule[ButtonEvaluator, Automatic]] ],
NotebookDefault, PageBreakAbove -> True, CellTags ->
GeneratedButtonBoxx=x+1]}, ClosingAutoSave -> True,
Editable -> False, WindowToolbars -> {}, PageWidth -> 299.5,
WindowSize -> {89., 29.}, WindowMargins -> {{92., Automatic},
{Automatic, 56.}}, WindowFrame -> Palette, WindowElements
-> {}, WindowFrameElements -> CloseBox, WindowClickSelect
-> False, ScrollingOptions -> {PagewiseScrolling -> True},
ShowCellBracket -> False, CellMargins -> {{0., 0.},
{Inherited, 0.}}, Active -> True, CellOpen -> True,
ShowCellLabel -> False, ShowCellTags -> False, ImageMargins
-> {{0., Inherited}, {Inherited, 0.}}, Magnification -> 1.5](*
********************************* *)Now, how do you create
such a button in less than a minute? ... :One way is to just
create a section cell and the underlying ButtonFunction
code as input cells, i.e., type interactively such that you
get something like:NotebookPut[Notebook[
{Cell[CellGroupData[ {Cell[x=x+1, Section],
Cell[If[!ValueQ[x], x=0], Input], Cell[x=x+1,
Input]}, Open]]}]]Then hit the F2B (function to
Button) button in ButtonTools.nb ( my freewarebutton tools
from http://www.mertig.com/mathdepot ) and you get the
button.With the HP and VP you can easily and quickly
generate (horizontally orverically) palettes. Check out
the Help button, or also the source code.It basically is
all straightforward and there is actually documentation about
all those ButtonFunction features somewhere. I agree that the
whole Button-design could have been made better, but up to a
point is quite useful. Of course the world is used to
better GUI's these days but if you really need nice
GUI's
and buttons, use Java and JLink ( and there are also simple
examples in the JLink manual of how to do this ).If you
don't like Java, go with VBA and use the nice Mahematica
for Active Xproduct from http://www.episoft.comRolf
MertigMertig
Consultinghttp://www.mertig.com
====
tryIn[1]:=Clear[a,b,
c,d,x,y]x= {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};y =
{a,b,c,d}; LinearSolve[x,y]s01=
LinearSolve[x,y][[1]]Out[4]={-a+b,-a+c,a-b-c+d,a}Out[5]=-a+
bIn[6]:=g[a_,b_]
=s01Out[6]=-a+bIn[7]:=g[1,3]Out[7]=2*NEVER* use capital
letters at the beginning of a variable's name!
Never!Matthias BodeSal. Oppenheim jr. & Cie.
KGaAKoenigsberger Strasse 29D-60487 Frankfurt am
MainGERMANYMobile: +49(0)172 6 74 95 77Internet:
http://www.oppenheim.de-----Ursprí.b9ngliche
Nachricht-----Gesendet: Freitag, 23. August 2002 06:25An:
mathgroup@smc.vnet.netBetreff: := Does not assign
variables properly.Why?Here's a piece of a conversion I had
with Mathematica.Why is a[A_,B_] := LinearSolve[X,Y][[1]]
not givingme the function I expect?In[261]:= X =
{{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};In[262]:= Y =
{A,B,C,D};In[263]:= LinearSolve[X,Y]Out[263]=
{-A+B,-A+C,A-B-C+D,A}In[264]:=
LinearSolve[X,Y][[1]]Out[264]= -A+BIn[265]:= a[A_,B_] :=
LinearSolve[X,Y][[1]]In[266]:= a[1,3]Out[266]= -A+BThe
output above is not what I want. I want 2. Here'swhat I
expect:In[267]:= a[A_,B_] := -A+B;In[268]:=
a[1,3]Out[268]= 2This output is what I expect. What is the
difference betweenthe two?
====
First of all, just look at
your own posting below. You clearly have a *(Times) where a ,
(comma) should be. Presumably your input ought to be:n = 5;
NDSolve[{D[[Sigma]norm[z, t], t] ==
3*z*Integrate[[Sigma]norm[z,t]^n*z, {z, 0, 1}] -
[Sigma]norm[z, t]^n, [Sigma]norm[z, 0] == 1.5*z,
[Sigma]norm[0, t] == 0},[Sigma]norm[z,t], {z, 0.01, 1},
{t, 0.01, 2}]However, even in the corrected version the
equation can't be solved. First of all you will get the
complaint:NDSolve::bcedge: Boundary conditions must be
specified at the edge of the spatial domain.In other
words Mathematica wants a boundary condition for
[Sigma]norm[z, 0.1] or alternatively you should use {z,0,1}
in NDSolve. But actually I do not think this equation is
solvable by any numerical scheme even if you could provide
the initial conditions at the edge of the boundary that
Mathematica requests. To evaluate the integral in your
equation NDSolve needs to know the values of
[Sigma]norm[z, t] for all z between 0 and 1 and a given t,
but this knowledge is not available at any stage of the
evaluation. I am not really an expert, but this seems to me
a clear example of an equation that is not solvable by any
numerical means.By the way, the fact that you know a
solution to a differential equation, and even the fact that
the solution is very simple does not imply that the equation
can be solved by any known method, except of course guessing,
which computer programs generally do not use. Andrzej
KozlowskiToyama International UniversityJAPANOn Friday,
August 23, 2002, at 05:25 AM, Toshiyuki ((Toshi)) Meshii >>
NDSolve seems to have difficulties with solving integral
equation.>> n = 5; NDSolve[{D[[Sigma]norm[z, t], t] == >
3*z*Integrate[[Sigma]norm[z,> t]^n*z, {z, 0, 1}] -
[Sigma]norm[z, t]^n,> [Sigma]norm[z, 0] == 1.5*z,
[Sigma]norm[0, t] == > 0}*[Sigma]norm[z,> t], {z, 0.01,
1}, {t, 0.01, 2}]>> Mathematica returns a message>>
NDSolve::deql: The first argument must have both an
equation and an > initial condition.>> which I cannot
understand.> Can anybody tell what's wrong with my
attempt?>>
-Toshi>
====
>Here's a piece of a conversion I had with
Mathematica.>Why is a[A_,B_] := LinearSolve[X,Y][[1]] not
giving>me the function I expect?>>In[261]:= X =
{{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};>In[262]:= Y =
{A,B,C,D};>In[263]:= LinearSolve[X,Y]>Out[263]=
{-A+B,-A+C,A-B-C+D,A}>In[264]:=
LinearSolve[X,Y][[1]]>Out[264]= -A+B>In[265]:= a[A_,B_] :=
LinearSolve[X,Y][[1]]>In[266]:= a[1,3]>Out[266]= -A+B>>The
output above is not what I want. I want 2. Here's>what I
expect:>>In[267]:= a[A_,B_] := -A+B;>In[268]:=
a[1,3]>Out[268]= 2>>This output is what I expect. What is the
difference between>the two?X={{0,0,0,1},{1,0,0,1},
{0,1,0,1},{1,1,1,1}};Y={A,B,C,D};a[A_,B_]:=
LinearSolve[X,Y][[1]];?aGlobal`aa[A_, B_] :=
LinearSolve[X,Y][[1]]Note that the RHS of the stored
definition is not a function of the arguments. Now add
Evaluate to RHSa[A_,B_]:=
Evaluate[LinearSolve[X,Y][[1]]];?aGlobal`aa[A_, B_] := -A
+ Ba[1,3]2Bob HanlonChantilly, VA USA
====
All of this
looks like a mistake to me because it seems far too easy.
But anyway, here is the solution that makes almost no use of
Mathematica. First of all, your equation is not a
differential equation so there is no point using
DSolve.Secondly the use of z in
Integrate[[Sigma]norm[z]^n*z, {z, 0, d}] is deceptive,
since you are integrating over z, so let's replace it by
something else, say s. So your equation
is:(3*z)/d^3)*Integrate[[Sigma]norm[s]^n*s, {s, 0, d}]
==[Sigma]norm[z]^nwhich is supposed to hold true for
every z>0. Re-write it asIntegrate[[Sigma]norm[s]^n*s,
{s, 0, d}]/d^3 =[Sigma]norm[z]^n/3zfor all z. However,
the left hand side is a function of d, independent of z, so
we can write:[Sigma]norm[z_]:=(3z*g[d])^(1/n)Let's take
this as a definition and substitute in the original
equationIn[2]:=Simplify[((3*z)*Integrate[[Sigma]norm[s]^
n*s, {s, 0, d}])/d^3 == [Sigma]norm[z]^n, {d > 0, n > 0, z
> 0}]Out[2]=TrueThat means you can take g to be an
arbitrary function of d.Andrzej KozlowskiToyama
International UniversityJAPANOn Friday, August 23, 2002,
at 05:25 AM, Toshiyuki ((Toshi)) Meshii > How can I solve
the following integral equation?> Mathematica seems not to
work.> Is there any way?>>
DSolve[((3*z)/d^3)*Integrate[[Sigma]norm[z]^n*z, {z, 0, d}]
==> [Sigma]norm[z]^n, [Sigma]norm[z], z]>> note: z>0 &
n>1>> I know that the answer is simple and> $B&R(Bnorm[z_]
= (1 + 1/(2*n))*(z/d)^(1/n)>> -Toshi>
====
But suddenly
the following Errormessage
appears:/usr/bin/local/mathematica: file or directory not
foundMandrake-updates ... but so far everything exceptof
Mathematica seems to work fine.)Of course I checked for the
File (it is indeed there) and (a hint from a Unix-usegroup)
the needed libs libc.so.5, libm.so.5 are in /lib/ too.Had
anyone had, ore better solved, a similar problem?greetings
Detlef
====
How can I create a Mathematica thing (function?
program?) that wouldautomatically open a browser page, and
give my username and pwd to log meinto a https:....
site? The server's login page has a script
resettingfields:
and the relevant input
cells areNicholas
====
Howdy,I'm trying to figure out
the correct syntax to do the following. I havesome function
with three arguments, and I want to syntactically describe
thesingle-argument function that holds two of those
arguments constant (i.e.without creating that
single-argument function).More specifically, I have
defined
Machine[radix_,multiplier_,state_] := Module [{c,s}, c =
Floor[state/base]; s = Mod[state,base]; multiplier*s + c
]where I have a generalize 'machine',
defined by the radix
and multiplier,which converts one state into another state.
So I'd like to be able to dosomething like this:
NestList[Machine[10,7,#], 3, 22]to get the series of states
that the radix-10 multiplier-7 machine runsthrough
(starting with state 3). However, this syntax doesn't seem
to
dowhat I want.I hope that description makes sense. It seems
like there must be a syntaxto describe the function
Machine[10,7,#].Anyone have any ideas?Bob H
====
>>There is
a following problem with Mathematica 4.2:>when i try to load
Help Browser, i get a message:>building help browser index
(first time only)>scanning index file>and
Mathematica stops
responding: you have to>kill process. There was no such a
problem with>version 4.1.>>Is there is a solution to
that?I'd start with the following
FAQ.http://support.wolfram.com/mathematica/interface/
helpbrowser/howrebuildindex.html-Dale
====
> There is a
following problem with Mathematica 4.2:> when i try to load
Help Browser, i get a message:> building help browser index
(first time only)> scanning index file> and
Mathematica stops
responding: you have to> kill process. There was no such a
problem with > version 4.1.> Is there is a solution to
that?> I have the exact same problem with 4.2 (on Win2K)
:(
====
>I'd start with the following
FAQ.>>http://support.wolfram.com/mathematica/interface/
helpbrowser/howrebuildindex.html>>-DaleSorry that i
failed say it immediately in a first place, but of coursei
did try it FAQ at first, and both tried to delete cache and
rebuildindex, but results where the same - whenever i try
to invoke help browser (or rebuild index, for that matter),
mathematica stops responding (i did read your answer to the
same question asked a week ago before - actually that is why
i turned to the FAQ).
====
People encounter this all the time.
It is because SelectionEvaluate does not do what you think.
It does not work like ToExpression, which causes immediate
kernel evaluation. Instead it works like when you press
Shift-Enter, which selects a cell for evaluation after all
current evaluations have finished.See
http://support.wolfram.com/mathematica/kernel/interface/
selectionevaluate.html-Dale>>Trying to manipulate
notebooks from the kernel I found>an unexpected bahavior
with Mathematica. First I tried>>the following commands one
by one (they are not int>the same cell, and they are not
selected at same time>for evaluation)>>nb =
NotebookCreate[];>i = 0;>(* Purpose is a Do loop here
*)>NotebookDelete[nb] (*1*)>NotebookWrite[nb, ++i, All]
(*2*)>SelectionEvaluate[nb] (*3*)>SelectionMove[nb, All,
Cell] (*4*)>>If I repeat evaluating coomands (*1,2,3,4*) one
by one>what is shown in the created notebook is an
animation>of the index i in the same cell.>Naturally a loop
must do the job. However when I>intent to collect
(*1,2,3,4*) in the same cell the>result is not the same even
whitout the Do loop (I>mean just evaluating this cell several
times)>>I would be grateful if some can explain what's
going>on here or if there is something wrong with
my>machine.>>Cesar>________________________________
__________________>Do You Yahoo!?>Yahoo! Finance - Get
real-time stock quotes>http://finance.yahoo.com
====
>Here's a
piece of a conversion I had with Mathematica.>Why is
a[A_,B_] := LinearSolve[X,Y][[1]] not giving>me the
function I expect?>>In[261]:= X =
{{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};>In[262]:= Y =
{A,B,C,D};>In[263]:= LinearSolve[X,Y]>Out[263]=
{-A+B,-A+C,A-B-C+D,A}>In[264]:=
LinearSolve[X,Y][[1]]>Out[264]= -A+B>In[265]:= a[A_,B_] :=
LinearSolve[X,Y][[1]]>In[266]:= a[1,3]>Out[266]= -A+B>>The
output above is not what I want. I want 2. Here's>what I
expect:>>In[267]:= a[A_,B_] := -A+B;>In[268]:=
a[1,3]>Out[268]= 2>>This output is what I expect. What is the
difference between>the two?This is a common misconception
about what := does. What it does is set up a variable
replacement for the unevaluated expression, not the evaluated
expression. Soa[A_,B_] := LinearSolve[X,Y][[1]]a[1,3]is
similar to doingReleaseHold[ Hold[ LinearSolve[X,Y][[1]] ]
/. {A->1, B->3}]which means that only explicit instances of
A and B are replaced. What you are attempting is done with
=. This assigns the function to the evaluated
expression.In[5]:=a[A_,B_] =
LinearSolve[X,Y][[1]]Out[5]=-A+BIn[6]:=a[1,3]Out[6]=2
There are certain situations where you get a different result
if you evaluate with the values or replace the values in the
symbolic evaluation. (This example is not one of them.) Using
= does the later. If you want to do the former, you should
use := and have the right hand side use A and B explicitly
or you could use a Block.In[7]:=a[b_,c_] := Block[{A=b,
B=c}, LinearSolve[X,Y][[1]]
]In[8]:=a[1,3]Out[8]=2-------------------------------------
-------------------------Omega ConsultingThe final answer
to your Mathematica needsSpend less time searching and more
time
finding.http://www.wz.com/internet/Mathematica.html
====
>
Normally I don't feel so stupid, but I'm
trying to create an
interactive>Mathematica notebook, and I'm stuck at square
one.>>Specifically, how do I do something like create a button
to add a number (or>perform other mathematical functions)
and then display or otherwise>manipulate the result
(eventually I want to be able to click a button
that>increments/decrements an angle and animate the
resulting transformation of a>vector, with an eye to finally
simulating a simple robotic arm complete with>simple
controls to manipulate the arm).>>I want to have a variable
(or matrix or whatever) defined as a global>variable x, and
then perform x = x+1 when a button is clicked. I've
been>using and programming computers for almost 25 years and
I can't follow>Wolfram's documentation. Is it
just me, or is
he always this obtuse when>explaining things? I mean, given
the amazing power of the Mathematica>system, a sample list
of buttons in a notebook that you could select and>examine
how they were implemented, would have been nice. I can't
find
such a>list, and this seems to be par for the course for
the rest of the>documentation as well.Button programming
can be very confusing at first. It has a whole series of
quirks that make it in many ways unique to Mathematica and
programming in general. This causes a lot of
head-scratching, but once you understand what's going on
things get easier.The key is to create a button that uses
the kernel (by default it only uses the front end). Here's
a simple example to help you get started.In[1]:=
x=1;In[2]:=ButtonBox[Increment x,Active->True,
ButtonEvaluator->Automatic, ButtonFunction:>Print[x =
,++x] ]//DisplayFormSome random things to note:-
ButtonEvaluator->Automatic. This says use the kernel to
implement the ButtonFunction.- Buttons only create
side-effects. They generate no output. What you see when you
press the button is the result of 2 side effects. One from ++,
which changes the value of x. The other from Print, which
creates a cell.- Print is, in general, a poor side-effect to
use in a button. It's difficult to control where
the Print
cell is placed. It is worth your while to learn how to use
other front end side-effect functions (such as NotebookRead
and NotebookWrite) when using buttons.Here are some further
resources you might find
helpful:http://support.wolfram.com/mathematica/interface/
buttons/http://library.wolfram.com/conferences/devconf99/
hinton/Buttons19991022.nbhttp://library.wolfram.com/
conferences/devconf2001/horton2/horton2.nb------------------
--------------------------------------------Omega
ConsultingThe final answer to your Mathematica needsSpend
less time searching and more time
finding.http://www.wz.com/internet/Mathematica.html
====
How
do I change format used for tick mark labels in a 2D plot? I
wouldlike to use DigitBlock->3 option of NumberForm to
format large numbersappearing as tick mark labels on a
histogram.Alexander
====
As Daniel Lichtblau pointed out,
the statement below about vertices is nonsense. Consider two
overlapping rectangles arranged as a cross. You need to
compute intersections and test them instead of
vertices.Begin forwarded message:>> Begin forwarded
message:>> Dear colleagues,>> any hints on how to implement a
very fast routine in Mathematica for> testing if two
rectangles have an intersection area?> Frank Brand> Here
is one approach.>> Given three points
{x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates
a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then>
Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on
your left as> you walk along the line though b and c in the
direction from b to c.> ( If the result is zero, then a lies
on the line.)>> The value of the determinant is
x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the
algorithm depends essentially on how fast this quantity can>
be computed. Suppose we write a function LeftSide[a,{b,c}]
that computes> the sign of the determinant.>> Now let
{p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a>
convex polygon traced counterclockwise. Then a lies within or
on the> boundary of the polygon if and only if none of the
numbers> LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does
not appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. .
.,pn,p1},2,1].>> Now use the fact that if two convex
polynomials overlap, then some> vertex of one of them must
lie inside or on the boundary of the other.>> If an overlap
of positive area is required, then the check is that only>
+1 appears--not that -1 does not appear.>> For two rectangles
( or parallelograms) this approach requires the> evaluation
of 16 determinants, so it may be a bit expensive. If the>
points have rational coordinates, then (positive)
denominators may be> cleared in the homogeneous coordinates
and the computations can be done> in integer arithmetic, at
the cost of at least three more> multiplications per
determinant.>>Garry HelzerDepartment of
MathematicsUniversity of MarylandCollege Park, MD
20742301-405-5176gah@math.umd.edu>>
====
While playing
arounf with patterns and substitutions, I came across
thefollowing behavior which I didn't expect:z :=
SomeHead[{{1, 2}, {3, 4}}]z /. {SomeHead[q_] ->
Flatten[q]}While this _does_ yield the desired result
{1,2,3,4}, Mathematica complains:Flatten::normal:
Nonatomic expression expected at position 1
inFlatten[q].........as if it is trying to evaluate
Flatten[q], with q not bound to{{1,2},{3,4}}.Could anybody
explain why this happens? Sidney Cadot
====
> While
playing arounf with patterns and substitutions, I came across
the> following behavior which I didn't expect:> z :=
SomeHead[{{1, 2}, {3, 4}}]> z /. {SomeHead[q_] ->
Flatten[q]}> While this _does_ yield the desired result
{1,2,3,4}, Mathematica complains:> Flatten::normal:
Nonatomic expression expected at position 1 in> Flatten[q].>
> ........as if it is trying to evaluate Flatten[q], with q
not bound to> {{1,2},{3,4}}.> Could anybody explain why
this happens?> Sidney Cadotduring the Replaceall (/.)
Mathematica first evaluate the ruleSomeHead[q_] ->
Flatten[q] . q is stilla symbol then and will bereplaces
when /. is used.You can avoid this Problem by using a
delayed rule SomeHead[q_] :>Flatten[q] or using thr Rule
Somehead->Flatten.Yours, Alexander-- / Alexander Dreyer,
Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer
Institut fuer Techno- und Wirtschaftsmathematik (ITWM)
Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663
Kaiserslautern /
====
> ............... I came across the>
following behavior which I didn't expect:>> z :=
SomeHead[{{1, 2}, {3, 4}}]> z /. {SomeHead[q_] ->
Flatten[q]}>> While this _does_ yield the desired result
{1,2,3,4}, Mathematicacomplains:>> Flatten::normal:
Nonatomic expression expected at position 1 in>
Flatten[q].>............> Could anybody explain why this
happens?Sidney,The clue is that, before any replacing is
done, z is evaluated to SomeHead[{{1, 2}, {3, 4}}];
SomeHead[q_] is evaluated to SomeHead[q_] Flatten[q] is
evaluated to Flatten[q] and the message is generatedsaying
essentially nothing to ßatten.*Then* the replacement
SomeHead[{{1, 2}, {3, 4}}] /. {SomeHead[q_] -> Flatten[q]}is
performed.It would be better here to use RuleDelayed, :>,
instead of Rule, ->, sinceFlatten[q] would not then be
evaluated. z:=SomeHead[{{1,2},{3,4}}]
z/.{SomeHead[q_]:>Flatten[q]}
{1,2,3,4}--Allan---------------------Allan
HayesMathematica Training and ConsultingLeicester
UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice
: +44 (0)116 271 4198
====
Never mind my question, I should
have used a delayed rule there (:> insteadof ->).Bit silly
of me.
====
Suppose f is a function of n real variables, and
returns avector of n real variables. What is the correct
syntax to find a rootof f using FindRoot?For instance, the
following works with n=7, but I would need to changethe
code if I changed the value of n:f[p_] := Table[fk[p, k],
{k,n}];pn = {p1,p2,p3,p4,p5,p6,p7};f1 := f[pn] [[1]];f2 :=
f[pn] [[2]];f3 := f[pn] [[3]];f4 := f[pn] [[4]];f5 := f[pn]
[[5]];f6 := f[pn] [[6]];f7 := f[pn] [[7]];theRoot =
FindRoot[{f1==0,f2==0,f3==0,f4==0,f5==0,f6==0,f7==0}, {p1,
1/n},{p2, 1/n},{p3, 1/n},{p4, 1/n},{p5, 1/n}, {p6, 1/n},{p7,
1/n}];-- John MacCormick Systems Research Center, HP Labs,
1501 Page Mill Road,
====
>I'm trying to figure out the correct
syntax to do the following. I have>some function with three
arguments, and I want to syntactically
describe>the>single-argument function that holds two of
those arguments constant (i.e.>without creating that
single-argument function).>>More specifically, I have
defined>> Machine[radix_,multiplier_,state_] := Module
[{c,s},> c = Floor[state/base]; s = Mod[state,base];>
multiplier*s + c> ]>>where I have a generalize
'machine',
defined by the radix and multiplier,>which converts one state
into another state. So I'd like to be able to>do>something
like this:>> NestList[Machine[10,7,#], 3, 22]>>to get the
series of states that the radix-10 multiplier-7 machine
runs>through (starting with state 3). However, this syntax
doesn't seem to>do>what I want.>>I hope that description
makes sense. It seems like there must be a syntax>to
describe the function Machine[10,7,#].>I assume that you
want base rather than radix in the definition (or vice
versa).Machine[base_, multiplier_, state_]:= Module[{c, s},
c=Floor[state/base]; s=Mod[state, base];
multiplier*s+c];NestList[Function[Machine[10,7,#]],3,22]{3,
21, 9, 63, 27, 51, 12, 15, 36, 45, 39, 66, 48, 60, 6, 42, 18,
57, 54, 33, 24, 30, 3}The abbreviation for Function[body] is
body&%==NestList[Machine[10, 7, #]&, 3, 22]TrueBob
HanlonChantilly, VA USA
====
>While playing arounf with
patterns and substitutions, I came across the>following
behavior which I didn't expect:>>z := SomeHead[{{1, 2}, {3,
4}}]>z /. {SomeHead[q_] -> Flatten[q]}>>While this _does_
yield the desired result {1,2,3,4}, Mathematica
complains:>>Flatten::normal: Nonatomic expression
expected at position 1 in>Flatten[q].>>........as if it is
trying to evaluate Flatten[q], with q not bound
to>{{1,2},{3,4}}.>>Could anybody explain why this
happens?z:=SomeHead[{{1,2},{3,4}}]The error is associated
with defining the Rule not executing it. Note that you get
the error with{SomeHead[q_]->Flatten[q]};Use
RuleDelayedz/.{SomeHead[q_]:>Flatten[q]}{1, 2, 3, 4}Bob
HanlonChantilly, VA USA
====
Can anyone help me with this
problem. If I have an n-element list, (say where each
element is itself alist), such as {{a,b}, {a,b}, {a,b}}is
there a way to strip off the outermost nesting of the list
toobtain just a sequence of of these n elements, that
is{a,b},{a,b},{a,b} so that I can use this for input for
some function.I would like to do something
likeOuter[SomeFunction, Table[{a,b},{N} ]] where I can
enter Ndynamically.The problem, of course, is that the
output of the Table command is onebig listand Outer is
expecting a sequence of N separate lists afterSomeFunction.
====
Bob, Apply[Sequence,{{a,b},{c,d}}] Sequence[{a,b},{c,d}]
Outer[F,Apply[Sequence,Table[{a,b},{3}]]]
{{{F[a,a,a],F[a,a,b]},{F[a,b,a],F[a,b,b]}},{{F[b,a,a],F[b,a,b
]},{F
[b,b,a],F[b,b,b]}}}---Allan---------------------Allan
HayesMathematica Training and ConsultingLeicester
UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice
: +44 (0)116 271 4198> Can anyone help me with this
problem.>> If I have an n-element list, (say where each
element is itself a> list), such as {{a,b}, {a,b}, {a,b}}>
is there a way to strip off the outermost nesting of the list
to> obtain just a sequence of of these n elements, that is>
{a,b},{a,b},{a,b} so that I can use this for input for some
function.>> I would like to do something like>
Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N>
dynamically.> The problem, of course, is that the output of
the Table command is one> big list> and Outer is expecting
a sequence of N separate lists after> SomeFunction.>>
====
>
Can anyone help me with this problem.> If I have an
n-element list, (say where each element is itself a> list),
such as {{a,b}, {a,b}, {a,b}}> is there a way to strip off
the outermost nesting of the list to> obtain just a sequence
of of these n elements, that is> {a,b},{a,b},{a,b} so that I
can use this for input for some function.> I would like to
do something like> Outer[SomeFunction, Table[{a,b},{N} ]]
where I can enter N> dynamically.> The problem, of course,
is that the output of the Table command is one> big list>
and Outer is expecting a sequence of N separate lists after>
SomeFunction.> Sequence@@{{a,b}, {a,b}, {a,b}}resp.
Apply[Sequence, {{a,b}, {a,b}, {a,b}}]will do it.CU,
Alexander-- / Alexander Dreyer, Dipl.-Math. - Abteilung
Adaptive Systeme / Fraunhofer Institut fuer Techno- und
Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse,
Geb. 7^2=49/313 D-67663 Kaiserslautern /
====
some function
with three arguments, and I want to syntactically describe
thesingle-argument function that holds two of those
arguments constant (i.e.without creating that
single-argument function).More specifically, I have
defined
Machine[radix_,multiplier_,state_] := Module [{c,s}, c =
Floor[state/base]; s = Mod[state,base]; multiplier*s + c
]where I have a generalize 'machine',
defined by the radix
and multiplier,which converts one state into another state.
So I'd like to be able to dosomething like this:
NestList[Machine[10,7,#], 3, 22]to get the series of states
that the radix-10 multiplier-7 machine runsthrough
(starting with state 3). However, this syntax doesn't seem
to
dowhat I want.I hope that description makes sense. It seems
like there must be a syntaxto describe the function
Machine[10,7,#].Anyone have any ideas?Bob
H
====
Sidney,With a direct rule Mathematica tries to
Flatten the symbol q immediately.You want a delayed rule to
avoid the error message.z /. SomeHead[q_] :>
Flatten[q]David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/{{
1,2},{3,4}}.Could anybody explain why this happens? Sidney
Cadot
====
You are quite right, Mathematica does evaluate
Flatten[q] before substituting {{1, 2}, {3, 4}}. It then
issues the error message and returns Flatten[q]. Only now
{{1, 2}, {3, 4}} is substituted for q, Flatten[{{1, 2}, {3,
4}}] is evaluated and you get the right answer. To avoid all
this just use RuleDelayed instead of Rule:In[1]:=z :=
SomeHead[{{1, 2}, {3, 4}}];In[2]:=z /. {SomeHead[q_] :>
Flatten[q]}Out[2]={1,2,3,4} Andrzej KozlowskiToyama
International UniversityJAPAN>> While playing arounf with
patterns and substitutions, I came across the> following
behavior which I didn't expect:>> z := SomeHead[{{1, 2}, {3,
4}}]> z /. {SomeHead[q_] -> Flatten[q]}>> While this _does_
yield the desired result {1,2,3,4}, Mathematica >
complains:>> Flatten::normal: Nonatomic expression
expected at position 1 in> Flatten[q].>> ........as if it is
trying to evaluate Flatten[q], with q not bound to>
{{1,2},{3,4}}.>> Could anybody explain why this happens?>
Sidney Cadot>>
====
> [...] Y = {A,B,C,D}; [...]>
In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]]> In[266]:=
a[1,3]> Out[266]= -A+B> The output above is not what I
want. I want 2.> [...]You are mixing the (global (*))
symbols A and B with the (local (*)) patterns A_ and B_. If
you want to replace the (global) solution with local values
you should writeIn[4]:= a[AA_, BB_] := LinearSolve[X,
Y][[1]] /. {A -> AA, B -> BB}; a[1, 3]Out[5]=
2________________(*) as far we can say that in Mathematica--
Rainer Gruber
====
> NestList[Machine[10,7,#], 3, 22]You
almost have it:NestList[Machine[10,7,#]&, 3, 22]More
elegantly, you can defined Machine this
way:Machine[radix_,multiplier_][state_] := ...Then you can
writeNestList[Machine[10,7], 3, 22]Tom Burton
====
> z :=
SomeHead[{{1, 2}, {3, 4}}]> z /. {SomeHead[q_] ->
Flatten[q]}> While this _does_ yield the desired result
{1,2,3,4}, Mathematica complains:> Flatten::normal:
Nonatomic expression expected at position 1 in>
Flatten[q].The -> operator is prompt: It permits evaluation
of the RHS Flatten[q]immediately, before it is used in the
substitution. Evidently, q wasundefined before you tried
this, so Flatten[q]'s evaluation yielded itself.Later, in
the process of substitution, with q set as you intended,
Flattenevaluated again, this time yielding the desired
result.Try it again after setting q to something. Then you
get not only thecomplaint but also the wrong answer.To
avoid these issues, use the delayed operator :> instead of
the promptoperator ->. A rule of thumb is: Use delayed
operators := and :> when theLHS (SomeHead[q_] in your case)
contains a blank (_).Tom Burton
====
Mark:In: ?KOut: K is
a default generic name for a summation index in a symbolic
sum.Turns out that there are seven single-letter
symbols.In: ClearAll[Global`*]; Select[Names[*],
(StringLength[#] == 1) &]Out: {C, D, E, I, K, N, O}K is a
little weird, because it's not Protected.In: Attributes[{C,
D, E, I, K, N, O}]Out: {{NHoldAll, Protected}, {Protected,
ReadProtected}, {Constant, Protected, ReadProtected},
{Locked, Protected, ReadProtected}, {}, {Protected},
{Protected, ReadProtected}}----Selwyn Hollis> I just
learned that K is a System` Symbol:> Information[K]>
Context[K]> I learned this due to an error message:>
Block[{K = 1}, Sum[j, {j, i}]]> The same message can be
generated by the following:> K := 1> Sum[j, {j, i}]> The
message can be eliminated by Removing K:> Remove[K]>
Block[{K = 1}, Sum[j, {j, i}]]> K := 1> Sum[j, {j, i}]>
Surely, this is not intentional.> --Mark.>
====
Dear
MathgroupI have convert pde to ode like thisdu_i/dt = 1-4
u_i + .02 (u_i-1 .9a 2 u_i + u i+1)/(delta (x))^3 + (u_i)^3
v_idv_i /dt = 3 u_i + .02 (v_i-1 .9a 2 v_i + u i+1)/(delta
(x))^3 - (u_I)^3 v_idelta(x)=(i)/(N+1)x_i=
(i)/(N+1)Boundary conditionu_0 (t) = 1 = u_N+1(t)v_0(t) =
3 = v_N+1(t),Initial conditiou_i(0) = 1+sin (2 pi x_i )v_i
= 3For i = 1,á., NTime Interval =[t_o, t_end] =
[0,10]Could i get code in Mathematica (by using Euler of 4
Runge - Kutta..)to solve this ordinary differential
equation.I am very happy if you give me
helpKhaled________________________________________________
_________________MSN Photos is the easiest way to share and
print your photos:
http://photos.msn.com/support/worldwide.aspx
====
> Dear
Mathgroup> I have convert pde to ode like this> du_i/dt =
1-4 u_i + .02 (u_i-1 ? 2 u_i + u i+1)/(delta (x))^3 + (u_i)^3
> v_i> dv_i /dt = 3 u_i + .02 (v_i-1 ? 2 v_i + u
i+1)/(delta (x))^3 - (u_I)^3 > v_i> delta(x)=(i)/(N+1)>
x_i= (i)/(N+1)> Boundary condition> u_0 (t) = 1 = u_N+1(t)>
v_0(t) = 3 = v_N+1(t),> Initial conditio> u_i(0) = 1+sin (2
pi x_i )> v_i = 3> For i = 1,?., N> Time Interval =[t_o,
t_end] = [0,10]Since this is 1+1 dimensional initial value
problem, Mathematica can do the discretization for you
automatically. Just useNDSolve[{ D[u[t, x], t] == 1 - 4
u[t, x] + 0.02 D[u[t, x], x, x] + u[t, x]^3 v[t, x], D[v[t,
x], t] == 3u[t, x] + 0.02 D[v[t, x], x, x] + u[t, x] ^3v[t,
x], u[t, 0] == u[t, 1] == 1, u[0, x] == 1 + Sin[2 Pi x], v[t,
0] == v[t, 1] == 3, v[0, x] == 3}, {u, v}, {t, 0, 10}, {x, 0,
1}]Mathematica by default uses fourth order differences
instead of the second order you specified above. If you
really want second order spatial differences with the exact
spacing you defined, you can useNDSolve[{D[u[t, x], t] == 1 -
4 u[t, x] + 0.02 D[u[t, x], x, x] + u[t, x]^3 v[t, x], D[v[t,
x], t] == 3u[t, x] + 0.02 D[v[t, x], x, x] + u[t, x] ^3v[t,
x], u[t, 0] == u[t, 1] == 1, u[0, x] == 1 + Sin[2 Pi x], v[t,
0] == v[t, 1] == 3, v[0, x] == 3}, {u, v}, {t, 0, 10}, {x, 0,
1}, StartingStepSize -> 1./206, MaxSteps -> {1000, 300},
DifferenceOrder -> 2]Interestingly enough, either way you do
it, Mathematica is only able to carry out the solution out
to about t == 0.035 or so. This appears to be because the
nonlinearity is causing the solution to form a
nonsingularity which appears as a cusp with rapidly rising
height.is because of the (delta (x))^3 in .02 (u_i-1 ? 2 u_i
+ u i+1)/(delta (x))^3 Any finite difference formula for the
second derivative on a uniform grid will involve (delta
(x))^2 -- i.e. squared, not cubed. At a fixed grid space, the
extra power will have the effect of making the diffusion
coefficient larger by a factor of n (which for your range of
interest effectively removes to formation of the
discontinuity). Presumably the (delta (x))^3 was a typo as
was the u_i+1 instead of v_i+1 in .02 (v_i-1 ? 2 v_i + u
i+1)However, if you really wanted the cubed power, here is
how you could manually do the discretization with
Mathematica:n = 205;X = N[Range[1, n]/(n + 1)];U[t_] =
Map[u[#][t] &, Range[1, n]];V[t_] = Map[v[#][t] &, Range[1,
n]];eqns = Join[ Thread[D[U[t], t] == 1 - 4 U[t] + 0.02
ListCorrelate[N[{1, -2, 1} n^3], U[t], {2, 2}, 1] + U[t]^3
V[t]], Thread[ D[V[t], t] == 3 U[t] + 0.02
ListCorrelate[N[{1, -2, 1} n^3], V[t], {2, 2}, 3] + U[t]^3
V[t]], Thread[U[0] == 1 + Sin[X]], Thread[V[0] == 3 + 0.
X]];NDSolve[eqns, Join[U[t], V[t]], {t, 0, 10}]> Could i
get code in Mathematica (by using Euler of 4 Runge -
Kutta..)to > solve this ordinary differential equation.I do
not recommend solving this with either an Euler method or a
RungeKutta method for the reason that the potential
formation of discontinuities could make the ODEs stiff. The
default method Mathematica uses automatically switches to
methods appropriate for stiff ODEs when needed. If you want
to use a RungeKutta method, you can useNDSolve[eqns,
Join[U[t], V[t]], {t, 0, 10}, Method->RungeKutta]This uses
the Runge-Kutta-Fehlberg 4(5) method.> I am very happy if you
give me help> Khaled>
_____________________________________________________________
____> MSN Photos is the easiest way to share and print your
photos: > http://photos.msn.com/support/worldwide.aspx>
====
I am a newbie to mathematica. I have a 14 functions
which are thefunction of r,theta and phi. I want to do some
mathematical operationover them. How can I do? Can it be
possible to call them in Do or Forloop with some index?
Please suggest. Raj
====
Is there an easy (elegant?) way to
generate the set of all k-tuplestaking values from some set
(list) S? I want the arguments of thefunction to be k (the
length of the tuples) and the set S. That
is,KTuples[3,{a,b}] should
produce{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b
,a},{b,b,b}}.
====
Bob, KTuples[n_,lst_]:=
Distribute[Table[{a,b},{n}],List] KTuples[3,{a,b}]
{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b
,b}}--Allan---------------------Allan HayesMathematica
Training and ConsultingLeicester
UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice
: +44 (0)116 271 4198> Is there an easy (elegant?) way to
generate the set of all k-tuples> taking values from some
set (list) S? I want the arguments of the> function to be k
(the length of the tuples) and the set S. That is,>
KTuples[3,{a,b}] should produce>
{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b
,b}}.>
====
Here's my
contestant:< Is there an easy (elegant?) way
to generate the set of all k-tuples> taking values from some
set (list) S? I want the arguments of the> function to be k
(the length of the tuples) and the set S. That is,>
KTuples[3,{a,b}] should produce>
{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b
,b}}.>
====
> Is there an easy (elegant?) way to generate the
set of all k-tuples> taking values from some set (list) S? I
want the arguments of the> function to be k (the length of
the tuples) and the set S. That is,> KTuples[3,{a,b}] should
produce>
{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b
,b}}.Here's a first implementation:ktuples[k_,
set_List] :=
Map[ set[[#]] &, Flatten[ Array[ List, Table[ Length[set],
{k}]], k - 1]]In[31]:=
ktuples[3,{a,b}]Out[31]={{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,
a,a},{b,a,b},{b,b,a},{b,b,b}}-Nevin
====
Does anyone know if
there are any publications that describe theintegration of
above?In particular I am working with a 4 gaussian process
with joint pdfp(x1,y1,x2,y2) transformed to->
p(r1,r2,theta1,theta2), the processeshave non-zero mean and
I would like to integrate the joint pdf twice(over r1 and r2)
and obtain an expression for the pdf of the phaseangles
between p(theta1,theta2). I could assume that the means are
thesame (to make life easier). Has anyone come accross this
- it doesn'tseem that unusual to me. I am asking because the
integrals arebecoming 'interesting'.thankyou for
any
tips.
====
Start Excel and go to Tools -> Macro ->
Security..., then on the SecurityLevel tab click on
Medium and then click OK.----- Original Message ----->>
> My original version of MathLink for Excel (MLX.xla) was for
Excel 97,and> It worked fine. Then I upgraded the package
to Excel 2000 by unloadingthe> macro from the Wolfram
site. It continued working perfectly on my old>
environment (Windows 98 + Mathematica 4.1).>> But I
recently upgraded to Mathematica 4.2 under Windows 2000; and
when> trying to load the macro (MLX.xla) for Excel2000, I
got (in Excel 2000)> the> following message: This
workbook contains a type of macro (Microsoft> Excel>
version 4.0 macro) that cannot be disable nor signed.
Therefore, this> workbook cannot be opened under high
security level.>> Does any one have any experience on
this?> Emilio Martin-Serrano>
====
Download the
newest patch from wolfram research - this should
theoreticallyhelp.> Group,>> My original version of
MathLink for Excel (MLX.xla) was for Excel 97, and> It
worked fine. Then I upgraded the package to Excel 2000 by
unloading the> macro from the Wolfram site. It continued
working perfectly on my old> environment (Windows 98 +
Mathematica 4.1).>> But I recently upgraded to Mathematica
4.2 under Windows 2000; and when> trying to load the macro
(MLX.xla) for Excel2000, I got (in Excel 2000)the>
following message: This workbook contains a type of macro
(MicrosoftExcel> version 4.0 macro) that cannot be disable
nor signed. Therefore, this> workbook cannot be opened under
high security level.>> Does any one have any experience on
this?> Emilio Martin-Serrano>
====
Find the link and
instructions on this
page:http://support.wolfram.com/applicationpacks/excel_link/
excelxp.html> Download the newest patch from wolfram
research - this shouldtheoretically> help.>> Group,>>
> My original version of MathLink for Excel (MLX.xla) was for
Excel 97,and> It worked fine. Then I upgraded the package
to Excel 2000 by unloadingthe> macro from the Wolfram
site. It continued working perfectly on my old>
environment (Windows 98 + Mathematica 4.1).>> But I
recently upgraded to Mathematica 4.2 under Windows 2000; and
when> trying to load the macro (MLX.xla) for Excel2000, I
got (in Excel 2000)> the> following message: This
workbook contains a type of macro (Microsoft> Excel>
version 4.0 macro) that cannot be disable nor signed.
Therefore, this> workbook cannot be opened under high
security level.>> Does any one have any experience on
this?> Emilio Martin-Serrano>
====
>I'm sorry for
that my question is not clear,I have correct below.> I have
a very interesting math problem:If I have a scales,and I>>
have 40 things that their mass range from 1~40 which each is
a nature>> number,and now I can only make 4 counterweights
to measure out each>> mass of those things.Question:What
mass should the counterweights>> be???>> The answer is that
1,3,9,27 and I wnat to use mathematica to solve>> this
problem.>> In fact,I think that this physical problem has
various>> answer,ex.2,4,10,28>> this way also work,because
if I have a thing which weight 3 , and I>> can measure out
by comparing 2<3<4 . But,If I want to solve this math>>
problem:>> {x|x=k1*a+k2*b+k3*c+k4*d}={1,2,3,4,,,,,,40} where
a,b,c,d is nature numbers.>> and {k1,k2,k3,k4}={1,0,-1}>>
How to solve it ?? >> mathematica solving method. appreciate
any idea sharing>> sincerely >> bryan>Just use brute
force.Needs[DiscreteMath`Combinatorica`];var = {a, b, c,
d}; n = Length[var];s = Outer[Times, var, {-1, 0, 1} ];f =
Flatten[Outer[Plus, Sequence@@s]];Since the length of f is
just 3^n then the range of numbersto be covered should be
{-(3^n-1)/2, (3^n-1)/2}.Consequently, the largest of the
weights can not exceed(3^n-1)/2 - (1+2+...+(n-1)) or
((3^n-1) - n(n-1))/234Thread[var->#]& /@ (First /@
Select[{var,f} /. Thread[var->#]& /@ KSubsets[Range[((3^n-1)
- n(n-1))/2], n], Sort[#[[2]]] ==
Range[-(3^n-1)/2,(3^n-1)/2]&]){{a -> 1, b -> 3, c -> 9, d ->
27}}Bob HanlonChantilly, VA USA
====
Can we please get a
response from WRI?i.e. regarding:In[1]:= Limit[
(Log[x]^Log[Log[x]])/ x , x->Infinity]Out[2]:=
InfinityIt
should be 0Jonathan Rockmannmtheory@msn.com
====
I'm
finding that the ImageSize option in Export has no effect when
exporting Cell or Notebook objects. For instance, the
following two commands produce precisely the same graphic:
Export[image1.jpg, Cell[Some cell contents, Text,
FontSize -> 100]] Export[image2.jpg, Cell[Some cell
contents, Text, FontSize -> 100], ImageSize -> {576,
288}]Has anyone encountered this problem before?(This is
with Mathematica 4.1.5 and Mac OS X.)----Selwyn
Hollisslhollis@mac.com
====
Does anyone know how to get the
JavaPlot window (or any windows of this type)which can be
seen at
http://www.wolfram.com/products/mathematica/newin42/
java.htmlthat WRI advertises comes with
4.2?Jonathanmtheory@msn.com
====
How can I get mathematica
to display the inverse of functions like:f(x) = x^2 - 7*x +
10orf(x) = cos(3*x + 1/2*pi)orf(x) = (x - 3) / (x +
2)I'm having trouble getting the syntax
right.
====
G'day,Looks like you forgot to define base in
your
Machine function and whenusing pure functions, don't forget
the ampersand.ThusNestList[Machine[10,7,#]&, 3,
22]returns{3, 8, 4, 2, 1, 7, 10, 5, 9, 11, 12, 6, 3, 8, 4,
2, 1, 7, 10, 5, 9, 11,12}with base = 2.Yas> Howdy,>> I'm
trying to figure out the correct syntax to do the following. I
have> some function with three arguments, and I want to
syntactically describe the> single-argument function that
holds two of those arguments constant (i.e.> without creating
that single-argument function).>> More specifically, I have
defined>> Machine[radix_,multiplier_,state_] := Module
[{c,s},> c = Floor[state/base]; s = Mod[state,base];>
multiplier*s + c> ]>> where I have a generalize
'machine',
defined by the radix and multiplier,> which converts one state
into another state. So I'd like to be able to do> something
like this:>> NestList[Machine[10,7,#], 3, 22]>> to get the
series of states that the radix-10 multiplier-7 machine
runs> through (starting with state 3). However, this syntax
doesn't seem to do> what I want.>> I hope that description
makes sense. It seems like there must be a syntax> to
describe the function Machine[10,7,#].>> Anyone have any
ideas?>> Bob H>
====
Some functions with vector arguments
work as expected and some giveerrors. I would appreciate if
someone can clarify why.First an example of a function
definition that works fine :f[u_,v_] := u.vCalling
it with
f[{x1,y1},{x2,y2}] gives the expected result x1 x2 +y1
y2.Now an example that does not work :g[u_,v_] :=
u-vCalling it with g[{x1,y1},{x2,y2}] one would expect the
answer {x1-x2,y1-y2} but instead one gets error
messages.Why ? And how do I fix g (i.e write a function that
outputs thedifference of 2 vectors).
====
I do not know why
you are getting a message, using your own code I get
theresult you expect.> Some functions with vector arguments
work as expected and some give> errors. I would appreciate if
someone can clarify why.>> First an example of a function
definition that works fine :> f[u_,v_] := u.v>
Calling it with
f[{x1,y1},{x2,y2}] gives the expected result x1 x2 +> y1 y2.>>
Now an example that does not work :> g[u_,v_] := u-v> Calling
it with g[{x1,y1},{x2,y2}] one would expect the answer
{x1-x2,> y1-y2} but instead one gets error messages.>> Why ?
And how do I fix g (i.e write a function that outputs the>
difference of 2 vectors).>>
====
> Now an example that does not
work :> g[u_,v_] := u-v> Calling it with g[{x1,y1},{x2,y2}]
one would expect the answer {x1-x2,> y1-y2} but instead one
gets error messagesWorks fine for me.Please check that you
have no existing definitions for the symbols used.
Clear[g,x1,x2,y1,y2]; g[u_,v_]:=u-v g[{x1,y1},{x2,y2}]
{x1-x2,y1-y2}--Allan---------------------Allan
HayesMathematica Training and ConsultingLeicester
UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice
: +44 (0)116 271 4198> Some functions with vector arguments
work as expected and some give> errors. I would appreciate
if someone can clarify why.>> First an example of a function
definition that works fine :> f[u_,v_] := u.v>
Calling it with
f[{x1,y1},{x2,y2}] gives the expected result x1 x2 +> y1 y2.>>
Now an example that does not work :> g[u_,v_] := u-v> Calling
it with g[{x1,y1},{x2,y2}] one would expect the answer
{x1-x2,> y1-y2} but instead one gets error messages.>> Why ?
And how do I fix g (i.e write a function that outputs the>
difference of 2 vectors).>>
====
> Some functions with vector
arguments work as expected and some give> errors. I would
appreciate if someone can clarify why.> First an example of
a function definition that works fine :> f[u_,v_]
:= u.v>
Calling it with f[{x1,y1},{x2,y2}] gives the expected result
x1 x2 +> y1 y2.> Now an example that does not work :>
g[u_,v_] := u-v> Calling it with g[{x1,y1},{x2,y2}] one
would expect the answer {x1-x2,> y1-y2} but instead one gets
error messages.> Why ? And how do I fix g (i.e write a
function that outputs the> difference of 2 vectors).> in
fact this call works fine on my Mathematicas (3.0 up to 4.1).
Did Youreally use the minus character? Maybe some erroneous
code was assignedto g before. Restart Mathematica or use
Remove[g] to really start upfrom the beginning.Sincerly
Alexander-- / Alexander Dreyer, Dipl.-Math. - Abteilung
Adaptive Systeme / Fraunhofer Institut fuer Techno- und
Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse,
Geb. 7^2=49/313 D-67663 Kaiserslautern /
====
Garry, Here's a
solution using your LeftSide concept; it works perfectly
but takes twice as much time as my solution. Both solutions
look at every vertex of both rectangles, but mine uses two
sides from each and yours requires looking at all four sides
of each rectangle. I'd think yours should be a triße
faster
than this, though. There may be efficiencies I'm
missing (in
both solutions). ClearAll[cis, rect, pickRect, extent,
cannotIntersect, intersects, daveRect] cis[t_] := {Cos@t,
Sin@t} rect[{pt : {_, _}, angle_, {len1_, len2_}}] :=
Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2
cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}] daveRect :=
{{Random[], Random[]}, Random[] + Pi/2, {Random[], Random[]}}
pickRect := rect@daveRect extent[r1_, r2_] := {Min@#, Max@#}
& /@ ((Take[r1, 2] - r1[[{2, 3}]]).Transpose@r2)
cannotIntersect[{{min1_, max1_}, {min2_, max2_}}] := max2 <
min1 || min2 > max1 intersects[r1_, r2_] := Catch[
If[cannotIntersect[#], Throw[False]] & /@
Flatten[Transpose[Outer[extent, {r1}, {r1, r2},
1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3, 2}], 1];
Throw[True]] ClearAll[leftSide,leftIntersects,sides]
sides[a_List]:=Partition[Join[a,{First@a}],2,1]
leftSide[{a_,b_},{{c_,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c
f>0 leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a
leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b
leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&
! Or@@(And@@#&/@leftSide[b,sides@a])
davePairs={daveRect,daveRect}&/@Range[10000];
rectanglePairs=Map[Reverse@rect[#]&,davePairs,{2}];
Timing[right=intersects[Sequence@@#]&/@rectanglePairs;]
Timing[test=leftIntersects[Sequence@@#]&/@rectanglePairs;]
right[Equal]test {3.187999999999999*Second, Null}
{6.765000000000001*Second, Null} True Bobby Treat
-----Original Message----- intersection > Begin forwarded
message: > Dear colleagues, > any hints on how to
implement a very fast routine in Mathematica for > testing if
two rectangles have an intersection area? > Frank Brand >
Here is one approach. > Given three points
{x1,y1},{x2,y2},{x3,y3}, switch to homogenous > coordinates
a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then >
Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on
your left as > you walk along the line though b and c in the
direction from b to c. > ( If the result is zero, then a lies
on the line.) > The value of the determinant is
x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the > speed of the
algorithm depends essentially on how fast this quantity can
> be computed. Suppose we write a function LeftSide[a,{b,c}]
that computes > the sign of the determinant. > Now let
{p1,p2, . . ., pn} be a list of vertices (pi={xi,yi}) of a >
convex polygon traced counterclockwise. Then a lies within or
on the > boundary of the polygon if and only if none of the
numbers > LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does
not appear in the > list LeftSide[a,#]&/@Partition[{p1,p2,. .
.,pn,p1},2,1]. > Now use the fact that if two convex
polynomials overlap, then some > vertex of one of them must
lie inside or on the boundary of the other. > If an overlap
of positive area is required, then the check is that only >
+1 appears--not that -1 does not appear. > For two
rectangles ( or parallelograms) this approach requires the >
evaluation of 16 determinants, so it may be a bit expensive.
If the > points have rational coordinates, then (positive)
denominators may be > cleared in the homogeneous coordinates
and the computations can be done > in integer arithmetic, at
the cost of at least three more > multiplications per
determinant. > Garry Helzer Department of Mathematics
University of Maryland College Park, MD 20742 301-405-5176
gah@math.umd.edu
====
I would like to have a list of all the
directives that can be used forcommand in the Windows Start
Menu). I am especially interested in adirective with which
you can appoint a file which has to be evaluated by
thekernel after it has been launched. I imagine that such
a directive lookslike -f filename, but I can not
find a list
of the correct directives.The Mathematica version I have is
4.1 on a Windows NT system.Rene Klaver
====
> 1) Get data
from excel into a coordinate > list {x,y,z}> e.g. Node 1,
{x1,y1,z1}> Node 2, {x2,y2,z2}> etc...Why not just use data
= ReadList[filename, Table[Number, {4}]];Alternatively,
data = ReadList[filename, Number, RecordLists->True]; data
= Partition[data, 4]; cord = {#[[1]], #[[2]], #[[3]]}& /@
data;> 2) Convert from Rectangular to > Cylindrical
(maybe)Coordinate tranforms live in
Calculus`VectorAnalysis`. It's straightforwardto write a
function that uses > 3) Plot3D the dataThis will be tricky
-- ListSurfacePlot3D plots f[x, y]. ListContourPlot3Dwhich
plots f[x, y, z] can be quite slow.> 4) Generate a harmonic
bessel function for that > plot3D/graph> 5) Find the
equation(s) that spits out > these harmonic > bessel
functions (which I think might be in the general form > of
Hankel > Function solutions to the Helmholtz equation which
shows > cylinder harmonics > of order v)Maybe I
misunderstand ... isn't this the same as fitting
a bessel
functionto your data? For this, you can use
Statistics`NonlinearFit`. > I can figure out step 5 if I can
get steps 1 through 4 > figured out. If > anyone can write a
recipe for me to follow that would be > great, or even some >
tips and clues...Anything!!!Dave.
====
You've gotten some very
helpful responses so I'm just going to add a coupleof
comments. The following is an example of yet another type of
button that you can useas a model. Copy and paste the
following code into a notebook. When youevaluate it, it
will create a button within the same notebook which
whenpressed evaluates the entire notebook. Sort of like
selecting from the menuis something in the notebook
already to evaluate. So input 1+2 (and don'thit enter)
somewhere in the notebook so that you can see whatthe
effect of the button
is.DisplayForm[Button[Evaluate*Notebook,ButtonFunction:>
FrontEndExecute[FrontEndToken[EvaluateNotebook]],
ButtonEvaluator->None,Active->True]]It has the nice feature
that it doesn't get stuck in a loop creating the button over
and over again. However, with some enthusiasm you can make
thishappen too.Personally, I am fascinated by the Java
integration in version 4.2. But I wouldn't recommend it to
anyone who is just starting to program in
Mathematica.Further, there is hardly enough material
contained in the Help Browser to make sense of much of
it.It is always a good idea to have several basic constructs
of efficient, usefulprograms that can serve as models when
programming. If you look atsome of the MathGroup archived
threads you will find similar complaints that the Mathematica
documentation is confusing.Jonathan
Rockmannmtheory@msn.com----- Original Message -----I want
to have a variable (or matrix or whatever) defined as a
globalvariable x, and then perform x = x+1 when a button is
clicked. I've beenusing and programming computers for
almost 25 years and I can't followWolfram's
documentation.
Is it just me, or is he always this obtuse whenexplaining
things? I mean, given the amazing power of the
Mathematicasystem, a sample list of buttons in a notebook
that you could select andexamine how they were implemented,
would have been nice. I can't find such alist,
and this
seems to be par for the course for the rest of
thedocumentation as well.
====
This was REALLY interesting.
Here's a solution that looks only at the7,560 relevant
combinations. It first chooses three numerators. Thenit
chooses two denominators for the first fraction. Then
twodenominators for the second fraction. The last fraction
is determinedat that point.<<
DiscreteMath`Combinatorica`ClearAll[f, g, h, j]r = Range[1,
9];f = KSubsets[#1, #2] &;g[r_List, n_Integer, {}] := f[r,
n]g[r_List, n_Integer, e_?VectorQ] := Join[e, #] & /@
f[Complement[r, e],n]g[r_List, n_Integer, e : {__?VectorQ}]
:= Flatten[g[r, n, #] & /@ e, 1]h[r_List, e : {__?VectorQ}]
:= Join[#, Complement[r, #]] & /@ ej[{a_, b_, c_, d_, e_,
f_, g_, h_, i_}] := a/(d e) + b/(f g) + c/(h
i)Timing[Select[h[r, Fold[g[r, #2, #1] &, {}, {3, 2, 2}]],
j@# == 1 &]]{0.532 Second, {{1, 5, 7, 3, 6, 8, 9, 2,
4}}}Hence the only solution is1/(3*6)+5/(8*9)+7/(2*4)Bobby
Treat-----Original Message-----University Professor of
Philanthropy and the LawDirector, National Center on
Philanthropy and the LawNew York University School of
LawRoom 206A110 West 3rd StreetNew York, N.Y.
10012-1074-----Original
Message-----byran__________________________________________
______________________________service. For more information
on a proactive anti-virus service workingaround the clock,
around the globe, visit
http://www.messagelabs.com__________________________________
______________________________________
====
Garry,Here's a
solution using your LeftSide concept; it works perfectly
buttakes twice as much time as my solution. Both solutions
look at everyvertex of both rectangles, but mine uses two
sides from each and yoursrequires looking at all four sides
of each rectangle. I'd think yoursshould be a triße
faster
than this, though. There may be efficienciesI'm
missing (in
both solutions).ClearAll[cis, rect, pickRect, extent,
cannotIntersect, intersects,daveRect]cis[t_] := {Cos@t,
Sin@t}rect[{pt : {_, _}, angle_, {len1_, len2_}}] :=
Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2
cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}]daveRect :=
{{Random[], Random[]}, Random[] + Pi/2,
{Random[],Random[]}}pickRect := rect@daveRectextent[r1_,
r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] -
r1[[{2,3}]]).Transpose@r2)cannotIntersect[{{min1_, max1_},
{min2_, max2_}}] := max2 < min1 || min2 >
max1intersects[r1_, r2_] := Catch[ If[cannotIntersect[#],
Throw[False]] & /@Flatten[Transpose[Outer[extent, {r1},
{r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3,
2}],1];
Throw[True]]ClearAll[leftSide,leftIntersects,sides]sides[a_
List]:=Partition[Join[a,{First@a}],2,1]leftSide[{a_,b_},{{c_
,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c
f>0leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a
leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b
leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&!
Or@@(And@@#&/@leftSide[b,sides@a])davePairs={daveRect,
daveRect}&/@Range[10000];rectanglePairs=Map[Reverse@rect[#]&
,davePairs,{2}];Timing[right=intersects[Sequence@@#]&/@
rectanglePairs;]Timing[test=leftIntersects[Sequence@@#]&/@
rectanglePairs;]right[Equal]test{3.187999999999999*Second
, Null}{6.765000000000001*Second, Null}TrueBobby
Treat-----Original Message-----intersection>> Begin
forwarded message:>> Dear colleagues,>> any hints on how to
implement a very fast routine in Mathematica for> testing if
two rectangles have an intersection area?> Frank Brand>
Here is one approach.>> Given three points
{x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates
a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then>
Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on
your leftas> you walk along the line though b and c in the
direction from b to c.> ( If the result is zero, then a lies
on the line.)>> The value of the determinant is
x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the
algorithm depends essentially on how fast this
quantitycan> be computed. Suppose we write a function
LeftSide[a,{b,c}] thatcomputes> the sign of the
determinant.>> Now let {p1,p2, . . ., pn} be a list of
vertices (pi={xi,yi}) of a> convex polygon traced
counterclockwise. Then a lies within or on the> boundary of
the polygon if and only if none of the numbers>
LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not
appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. .
.,pn,p1},2,1].>> Now use the fact that if two convex
polynomials overlap, then some> vertex of one of them must
lie inside or on the boundary of the other.>> If an overlap
of positive area is required, then the check is thatonly>
+1 appears--not that -1 does not appear.>> For two rectangles
( or parallelograms) this approach requires the> evaluation
of 16 determinants, so it may be a bit expensive. If the>
points have rational coordinates, then (positive)
denominators may be> cleared in the homogeneous coordinates
and the computations can bedone> in integer arithmetic, at
the cost of at least three more> multiplications per
determinant.>>Garry HelzerDepartment of
MathematicsUniversity of MarylandCollege Park, MD
20742301-405-5176gah@math.umd.edu>>
====
Garry,Also note
your solution requires rectangle points to be in
clockwiseorder (mine doesn't), but yours works for
arbitrary convex polygons aswritten.Bobby-----Original
Message-----ClearAll[cis, rect, pickRect, extent,
cannotIntersect, intersects,daveRect]cis[t_] := {Cos@t,
Sin@t}rect[{pt : {_, _}, angle_, {len1_, len2_}}] :=
Module[{pt2}, {pt, pt2 = pt + len1 cis[angle], pt2 - len2
cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}]daveRect :=
{{Random[], Random[]}, Random[] + Pi/2,
{Random[],Random[]}}pickRect := rect@daveRectextent[r1_,
r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] -
r1[[{2,3}]]).Transpose@r2)cannotIntersect[{{min1_, max1_},
{min2_, max2_}}] := max2 < min1 || min2 >
max1intersects[r1_, r2_] := Catch[ If[cannotIntersect[#],
Throw[False]] & /@Flatten[Transpose[Outer[extent, {r1},
{r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3,
2}],1];
Throw[True]]ClearAll[leftSide,leftIntersects,sides]sides[a_
List]:=Partition[Join[a,{First@a}],2,1]leftSide[{a_,b_},{{c_
,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c
f>0leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a
leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b
leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&!
Or@@(And@@#&/@leftSide[b,sides@a])davePairs={daveRect,
daveRect}&/@Range[10000];rectanglePairs=Map[Reverse@rect[#]&
,davePairs,{2}];Timing[right=intersects[Sequence@@#]&/@
rectanglePairs;]Timing[test=leftIntersects[Sequence@@#]&/@
rectanglePairs;]right[Equal]test{3.187999999999999*Second
, Null}{6.765000000000001*Second, Null}TrueBobby
Treat-----Original Message-----intersection>> Begin
forwarded message:>> Dear colleagues,>> any hints on how to
implement a very fast routine in Mathematica for> testing if
two rectangles have an intersection area?> Frank Brand>
Here is one approach.>> Given three points
{x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates
a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then>
Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on
your leftas> you walk along the line though b and c in the
direction from b to c.> ( If the result is zero, then a lies
on the line.)>> The value of the determinant is
x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the
algorithm depends essentially on how fast this
quantitycan> be computed. Suppose we write a function
LeftSide[a,{b,c}] thatcomputes> the sign of the
determinant.>> Now let {p1,p2, . . ., pn} be a list of
vertices (pi={xi,yi}) of a> convex polygon traced
counterclockwise. Then a lies within or on the> boundary of
the polygon if and only if none of the numbers>
LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not
appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. .
.,pn,p1},2,1].>> Now use the fact that if two convex
polynomials overlap, then some> vertex of one of them must
lie inside or on the boundary of the other.>> If an overlap
of positive area is required, then the check is thatonly>
+1 appears--not that -1 does not appear.>> For two rectangles
( or parallelograms) this approach requires the> evaluation
of 16 determinants, so it may be a bit expensive. If the>
points have rational coordinates, then (positive)
denominators may be> cleared in the homogeneous coordinates
and the computations can bedone> in integer arithmetic, at
the cost of at least three more> multiplications per
determinant.>>Garry HelzerDepartment of
MathematicsUniversity of MarylandCollege Park, MD
20742301-405-5176gah@math.umd.edu>>
====
Try
this:Off[Remove::rmnsm]Remove[Global`p@,
Global`p@@]n = 7;pn = Unique[p] & /@ Range[10]f[p_]
= Array[fk[p, #] &, n]f[p]fEq[p_] = MapThread[Equal, {f[p],
Array[0 &, n]}]Bobby Treat-----Original Message-----f2 :=
f[pn] [[2]];f3 := f[pn] [[3]];f4 := f[pn] [[4]];f5 :=
f[pn] [[5]];f6 := f[pn] [[6]];f7 := f[pn] [[7]];theRoot =
FindRoot[{f1==0,f2==0,f3==0,f4==0,f5==0,f6==0,f7==0}, {p1,
1/n},{p2, 1/n},{p3, 1/n},{p4, 1/n},{p5, 1/n}, {p6, 1/n},{p7,
1/n}];-- John MacCormick Systems Research Center, HP Labs,
1501 Page Mill Road,
====
the problem, but I duplicated it
just now, so I'm puzzled. I'm usingWindows XP
Home, and
System`Private`$BuildNumber is 168634.4.2 for Microsoft
Windows (June 5, 2002)f[n_] :=
Log[n]^Log[Log[n]]Limit[f[n]/n, n ->
Infinity]InfinityBobby
Treat -----Original Message----- By the way, Mathematica
gets the following limit wrong:f[n_] :=
Log[n]^Log[Log[n]]Limit[f[n]/n, n ->
Infinity]InfinityThat
limit is zero. For the Sieve to be polynomial, we only need
thesequence to be BOUNDED (for some power of n in the
denominator).Bobby Treat
====
Garry,No, you don't have to
compute intersections, and yes, you can testvertices only.
I haven't coded it yet, but the LeftSide idea seemslike
a good one.It is sufficient to test whether all vertices of
one convex polygon areon the left (out) side of some side
of the second polygon (both polygonsin clockwise order). If
that happens for any side of either polygon,the polygons
don't intersect. In the cross example, some vertices
areto the right for every side you try.Bobby
Treat-----Original Message-----intersection>> Begin
forwarded message:>> Dear colleagues,>> any hints on how to
implement a very fast routine in Mathematica for> testing if
two rectangles have an intersection area?> Frank Brand>
Here is one approach.>> Given three points
{x1,y1},{x2,y2},{x3,y3}, switch to homogenous> coordinates
a={1,x1,y1}, b={1,x2,y2}, c={1,x3,y3}. Then>
Sign[Det[{a,b,c}]] is +1 if and only if the point a lies on
your leftas> you walk along the line though b and c in the
direction from b to c.> ( If the result is zero, then a lies
on the line.)>> The value of the determinant is
x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the> speed of the
algorithm depends essentially on how fast this
quantitycan> be computed. Suppose we write a function
LeftSide[a,{b,c}] thatcomputes> the sign of the
determinant.>> Now let {p1,p2, . . ., pn} be a list of
vertices (pi={xi,yi}) of a> convex polygon traced
counterclockwise. Then a lies within or on the> boundary of
the polygon if and only if none of the numbers>
LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not
appear in the> list LeftSide[a,#]&/@Partition[{p1,p2,. .
.,pn,p1},2,1].>> Now use the fact that if two convex
polynomials overlap, then some> vertex of one of them must
lie inside or on the boundary of the other.>> If an overlap
of positive area is required, then the check is thatonly>
+1 appears--not that -1 does not appear.>> For two rectangles
( or parallelograms) this approach requires the> evaluation
of 16 determinants, so it may be a bit expensive. If the>
points have rational coordinates, then (positive)
denominators may be> cleared in the homogeneous coordinates
and the computations can bedone> in integer arithmetic, at
the cost of at least three more> multiplications per
determinant.>>Garry HelzerDepartment of
MathematicsUniversity of MarylandCollege Park, MD
20742301-405-5176gah@math.umd.edu>>
====
> Dear All:> I want
to make an animation that simulate the Doppler Effect, just
2D> circles travel out one by one, and at the same time,the
origin of the> wave also moves toward one direction. I have
no idea to make the speed> of the wave origin and the speed
of traveling wave independent.Is> sincerely bryancircles,
but the second one includes two lines which approximate
theshock waves, I believe. The arguments of the functions
are vx & vy(velocities in x & y directions) and tstart,
tend, tstep whichdetermine how many circles to draw and the
spacing of the circles. Ijust used the Do loop to make the
pictures, & then you can select thecells & pick
Animate.dopp[vx_,vy_,tstart_,tend_,tstep_]:=Show[Graphics
[Table[{Hue[t/tend],Circle[{vx*t,vy*t},tend-t]},{t,tstart,
tend,tstep}]],AspectRatio->Automatic,Axes->True,PlotLabel->
Mach
Sqrt(vx^2+vy^2)];doppcone[vx_,vy_,tend_,tstep_]:=Show[
Graphics[Table[{Hue[t/tend],Circle[{vx*t,vy*t},tend-t]},{t,0
,tend,tstep}]],Graphics[Line[{{-tend*Sin[If[vx==0,0,ArcTan[
vy/vx]]],tend*Cos[If[vx==0,0,ArcTan[vy/vx]]]},{Sign[vx]*Cos[
If[vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx^2+vy^2]-
tstep*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sin[If[vx==0,0,ArcTan[
vy/vx]]]*Sign[vx]*(tend-tstep)*sqrt[vx^2+vy^2]+tstep*Cos[If[
vx==0,0,ArcTan[vy/vx]]]}}]],Graphics[Line[{{tend*Sin[If[vx==
0,0,ArcTan[vy/vx]]],-tend*Cos[If[vx==0,0,ArcTan[vy/vx]]]},{
Sign[vx]*Cos[If[vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx^
2+vy^2]+tstep*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sign[vx]*Sin[If
[vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*srt[vx^2+vy^2]-tstep
*Cos[If[vx==0,0,ArcTan[vy/vx]]]}}]],AspectRatio->Automatic,
Axes->True];Do[dopp[i,0,0,10,1],{i,0,1.4,0.2}];Hope I did
that without typos - I can't see how to post the
notebook
====
Neat!The animation was jagged, though, so I
fixed the text position and the imagesize; it
won't work
for large vertical
velocities:margin=.8;dopp[vx_,vy_,tend_,tstep_]:=Show[
Graphics[ {Table[{Hue[t/tend],Circle[{vx*t,vy*t},tend-t]},
{t,0,tend,tstep}], Text[Mach <>ToString@Sqrt[vx^2+vy^2]
,{0,.5+tend},{-1,0}] }],AspectRatio->Automatic,Axes->True,
PlotRange-> {{-tend-margin,margin+Max[tend,(vx tend)+.5]},
{-tend-margin,2margin+Max[tend,(vy tend)]}},
Ticks->{{-10,-5,0,5,10},Automatic}, ImageSize->{10 2
margin+10 (tend+Max[tend,(vx tend)+.5]), 10 3 margin+10(tend
+Max[tend,(vy tend)])}];Do[dopp[i,0,10,1],{i,0,1.4,0.2}];By
the way to avoid the slashes, CopyAs/TextOnly.> Dear All:>
I want to make an animation that simulate the Doppler Effect,
just 2D> circles travel out one by one, and at the same
time,the origin of the> wave also moves toward one
direction. I have no idea to make the speed> of the wave
origin and the speed of traveling wave independent.Is>
sincerely bryan>> circles, but the second one includes two
lines which approximate the> shock waves, I believe. The
arguments of the functions are vx & vy> (velocities in x & y
directions) and tstart, tend, tstep which> determine how many
circles to draw and the spacing of the circles. I> just used
the Do loop to make the pictures, & then you can select the>
cells & pick
Animate.>>dopp[vx_,vy_,tstart_,tend_,tstep_]:=Show[
Graphics[Table[{Hue[t/tend],Circle[{vx*t,vy*t},tend-t]},{t,
tstart,tend,tstep}]],AspectRatio->Automatic,Axes->True,
PlotLabel->Mach> Sqrt(vx^2+vy^2)];>>
doppcone[vx_,vy_,tend_,tstep_]:=Show[Graphics[Table[{Hue[t/
tend],Circle>[{vx*t,vy*t},tend-t]},{t,0,tend,tstep}]],
Graphics[Line[{{-tend*Sin[If[vx==0,0,ArcTan[vy/vx]]],tend*
Cos[If[vx==0,0,ArcTan[vy/vx]]]},{Sign[vx]*Cos[If[vx==0,0,
ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx^2+vy^2]>
-tstep*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sin[If[vx==0,0,ArcTan[
vy/vx]]]*Sign[vx]*(tend-tstep)*sqrt[vx^2+vy^2]+tstep*Cos[If[
vx==0,0,ArcTan[vy/vx]]]}}]],Graphics[Line[{{tend*Sin[If[vx=
=0,0,ArcTan[vy/vx]]],-tend*Cos[If[vx==0,0,ArcTan[vy/vx]]]},
{Sign[vx]*Cos[If[vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*sqrt[vx
^2+vy^2]+tstep*Sin[If[vx==0,0,ArcTan[vy/vx]]],Sign[vx]*Sin[
If[vx==0,0,ArcTan[vy/vx]]]*(tend-tstep)*s>rt[vx^2+vy^2]-
tstep*Cos[If[vx==0,0,ArcTan[vy/vx]]]}}]],AspectRatio->
Automatic,Axes->True];>
Do[dopp[i,0,0,10,1],{i,0,1.4,0.2}];>> Hope I did that
without typos - I can't see how to post the notebook>
====
It
would take me a lot of time to understand howfunctions like
SelectionEvaluate works...Cesar.> People encounter this all
the time. It is because> SelectionEvaluate does > not do
what you think. It does not work like> ToExpression, which
causes > immediate kernel evaluation. Instead it works like>
when you press > Shift-Enter, which selects a cell for
evaluation> after all current > evaluations have finished.>
See
>http://support.wolfram.com/mathematica/kernel/interface/
selectionevaluate.html> -Dale>
__________________________________________________Do You
Yahoo!?Yahoo! Finance - Get real-time stock
quoteshttp://finance.yahoo.com
====
> How can I get
mathematica to display the inverse of functions like:> f(x)
= x^2 - 7*x + 10> or> f(x) = cos(3*x + 1/2*pi)> or>
f(x) = (x - 3) / (x + 2)> I'm having trouble getting the
syntax right.> Solve[y==x^2-7*x+10, x]{{x -> (1/2)*(7 -
Sqrt[9 + 4*y])}, {x -> (1/2)*(7 + Sqrt[9 + 4*y])}}x^2-7*x+10
/. % // ExpandAll{y, y}Solve[y == Cos[3*x+1/2*Pi], x]{{x ->
-(ArcSin[y]/3)}}Cos[3*x+1/2*Pi] /. %{y}Solve[y ==
(x-3)/(x+2), x]{{x -> (-3 - 2*y)/(-1 + y)}}(x-3)/(x+2) /. %
// Simplify{y}Bob HanlonChantilly, VA USA
====
> I am a
newbie to mathematica. I have a 14 functions which are the>
function of r,theta and phi. I want to do some mathematical
operation> over them. How can I do? Can it be possible to
call them in Do or For> loop with some index?> As a general
rule avoid Do and For loops and just operate on Lists or Map
(/@) onto lists.g /@ {f1[r,theta,phi], f2[r,theta,phi],
f3[r,theta,phi]}{g[f1[r, theta, phi]], g[f2[r, theta, phi]],
g[f3[r, theta, phi]]}This can be written more compactly
asg /@ (#[r,theta,phi]& /@ {f1,f2,f3}){g[f1[r, theta,
phi]], g[f2[r, theta, phi]], g[f3[r, theta, phi]]}Bob
HanlonChantilly, VA USA
====
> Is there an easy (elegant?)
way to generate the set of all k-tuples> taking values from
some set (list) S? I want the arguments of the> function to
be k (the length of the tuples) and the set S. That is,>
KTuples[3,{a,b}] should produce>
{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b
,b}}.> kTuples[n_Integer?Positive, s_List] :=
Flatten[Outer[List, Sequence@@Table[s,{n}]],n-1];s =
{a,b};kTuples[3, {a,b}]{{a, a, a}, {a, a, b}, {a, b, a}, {a,
b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b,
b}}Length[kTuples[10, {a,b}]]1024Bob HanlonChantilly, VA
USA
====
> If I have an n-element list, (say where each
element is itself a> list), such as {{a,b}, {a,b}, {a,b}}>
is there a way to strip off the outermost nesting of the list
to> obtain just a sequence of of these n elements, that is>
{a,b},{a,b},{a,b} so that I can use this for input for some
function.> I would like to do something like>
Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N>
dynamically.> The problem, of course, is that the output of
the Table command is one> big list> and Outer is expecting
a sequence of N separate lists after> SomeFunction.> Use
SequencekTuples[n_Integer?Positive,s_List]:=
Flatten[Outer[List,Sequence@@Table[s,{n}]],n-1];s =
{a,b,c,d,e}; n =3;Length[kTuples[n,s]] ==
Length[s]^nTrueBob HanlonChantilly, VA
USA
====
f[Sequence@@{{a,b}, {a,b}, {a,b}}]f[{a, b}, {a, b},
{a, b}]Bobby Treat-----Original
Message-----dynamically.The problem, of course, is that the
output of the Table command is onebig listand Outer is
expecting a sequence of N separate lists afterSomeFunction.
====
f[x_] = x^2 - 7*x + 10g[x_] = Cos[3*x + 1/2*Pi]h[x_] =
(x - 3)/(x + 2)Off[Solve::ifun]Solve[f[x] == y,
x]Solve[g[x] == y, x]Solve[h[x] == y, x]Bobby
Treat-----Original Message-----
====
f[x_] = x^2 - 7*x +
10;g[x_] = Cos[3*x + 1/2*Pi];h[x_] = (x - 3)/(x + 2);#[x] &
/@ {f, g, h}{10 - 7*x + x^2, -Sin[3*x], (-3 + x)/(2 +
x)}Bobby Treat-----Original Message-----
====
I get the
expected results. I suspect g was already defined at
thetime. For instance you might have set g={a,b}
previously. ClearAll[g]goes before defining the function
g.Bobby Treat-----Original Message-----Calling it with
g[{x1,y1},{x2,y2}] one would expect the answer {x1-x2,y1-y2}
but instead one gets error messages.Why ? And how do I fix g
(i.e write a function that outputs thedifference of 2
vectors).
====
In[1]:=ktuples[n_Integer, d_List] :=
Flatten[Outer[List, Sequence @@ Table[d, {n}]],
2]In[2]:=ktuples[3, {a, b}]Out[2]={{a, a, a}, {a, a, b},
{a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b, a}, {b, b,
b}}Tomas GarzaMexico City----- Original Message -----
====
kTuples[k_Integer?Positive, s_List] :=
Partition[Flatten@Outer[List,Sequence @@ (s & /@ Range[k])],
k]kTuples[3, {a, b}]Bobby Treat-----Original
Message-----Sender: steve@smc.vnet.netApproved: Steven M.
Christensen , Moderator
====
The trick is
to use the Sequence Function. Try the following code and
youwill see how it works.abcd = CharacterRange[a,
d]abcd1 = Flatten[Outer[{#1, #2} &, abcd, abcd], 1]abcd2
= Outer[First[#]*Last[#] &, Sequence[abcd1], 1]abcd2 uses the
list of lists you have created to load as a sequence
ofarguments to outer. You need the third argument to
operate on the parts ofthe list if this is your goal.Read
the description of Sequence. It also works in contexts other
thanOuter.Richard Palmer> Can anyone help me with this
problem.> If I have an n-element list, (say where each
element is itself a> list), such as {{a,b}, {a,b}, {a,b}}>
is there a way to strip off the outermost nesting of the list
to> obtain just a sequence of of these n elements, that is>
{a,b},{a,b},{a,b} so that I can use this for input for some
function.> I would like to do something like>
Outer[SomeFunction, Table[{a,b},{N} ]] where I can enter N>
dynamically.> The problem, of course, is that the output of
the Table command is one> big list> and Outer is expecting
a sequence of N separate lists after> SomeFunction.>
====
Dear GroupI would like to know, if is possible to
solveIntegrate[(exp[-a/x])/(x^2-b^2),{x,0,infinity}] witha
and b constant ( Real )using Mathematica.Valdeci
Mariano*****************************************************
****************Valdeci Mariano de SouzaMasterÇs Degree of
Applied Physics - Unesp/Rio Claro - State of S.8boPaulo -
BrazilLaboratory of Electrical Measurementsphone : (
0XX19 ) 526 -
2237*********************************************************
************
====
> Is there an easy (elegant?) way to generate
the set of all k-tuples> taking values from some set (list)
S? I want the arguments of the> function to be k (the length
of the tuples) and the set S. That is,> KTuples[3,{a,b}]
should produce>
{{a,a,a},{a,a,b},{a,b,a},{a,b,b},{b,a,a},{b,a,b},{b,b,a},{b,b
,b}}.Method 1:Distribute[Table[{a,b},{3}],List]Method
2:Needs[DiscreteMath`Combinatorica`];Strings[{a,b},3]
Rob PrattDepartment of Operations
Researchhttp://www.unc.edu/~rpratt/
====
> Does anyone know
how to get the JavaPlot window (or any windows of this
type)> which can be seen at >
http://www.wolfram.com/products/mathematica/newin42/java.html
> that WRI advertises comes with 4.2?Well, I don't know if
any tools (like that Window/Palette) written in Java are in
the M_4.2 box, but if you know a little Java Programming,
you can easily write something like that yourself; eg. using
the MathGraphicsJPanel which allows you to display
Mathematica GraphicsExpressions in a Java Component, simply
by calling its setCommand()Method (I hope that's correct, I
am writing that from memory); eg. a simple JFrame with a
MathGraphicsJPanel would be programmed likethis: (* This
code is necessary for setting up J/Link
*)< {NumberPoint -> ,}] ;However, Import
is not the function I'd like to use, because it is
realyslow over large files.I wonder if someone knows a way
to use something faster than Import (I namely think of
ReadList) with coma-numbers?
====
I'm a poor physicist trying
to figure out how to sort out thephysical from the
non-physical solutions to a problem. To dothat, I need
to be able to look at an expression and pick out
asubexpression, the part under the radical.For example,
say I've got the expression a b x^2 + 5 x^3 + 5 Sqrt[4 -
x^2]I'd like to pick out 4 - x^2, which would then tell me
that x isbetween +/- 2. I know there has got to be an easy
way to do it, but Ican't find it. Any help would
be
appreciated.Steve
Beachasb4@psu.eduhttp://www.thebeachfamily.org
====
I had
looked at using Cases, but had gotten tripped up
byforgettting to use Infinity to tell it to look at all
subexpressions. The tip from Bob Hanlon about how to use
Algebra`InequalitySolve`package helped too.> I'm a poor
physicist trying to figure out how to sort out the>
physical from the non-physical solutions to a problem.
To do> that, I need to be able to look at an expression and
pick out a> subexpression, the part under the radical.>
For example, say I've got the expression > a b x^2 + 5 x^3
+ 5 Sqrt[4 - x^2]> I'd like to pick out 4 - x^2, which
would then tell me that x is> between +/- 2. I know there
has got to be an easy way to do it, but I> can't
find it. Any
help would be appreciated.> Steve Beach> asb4@psu.edu>
http://www.thebeachfamily.org
====
expr=a b x^2+5 x^3+5
Sqrt[4-x^2];First note that Mathematica interprets Sqrt[u]
as u^(1/2) FullForm[Sqrt[u]] Power[u,Rational[1,2]]Now we
can find the list of all u from subexpressions the form
Sqrt[u_]: Cases[expr, u_^(1/2) ->u,{0, Infinity}] {4 -
x^2}Here {0, Infinity} causes the search to be over
subexpressions at alllevels including level 0, which is
the whole expression. The search willnot go inside
heads unless we specify this: Cases[expr[y], u_^(1/2) ->
u, {0, Infinity}] {} Cases[expr[y], u_^(1/2) -> u, {0,
Infinity}, Heads -> True] {4 -
x^2}--Allan---------------------Allan HayesMathematica
Training and ConsultingLeicester
UKwww.haystack.demon.co.ukhay@haystack.demon.co.ukVoice
: +44 (0)116 271 4198> I'm a poor physicist trying to
figure
out how to sort out the> physical from the
non-physical solutions to a problem. To do> that, I need
to be able to look at an expression and pick out a>
subexpression, the part under the radical.>> For example, say
I've got the expression>> a b x^2 + 5 x^3 + 5 Sqrt[4 -
x^2]>>
I'd like to pick out 4 - x^2, which would then tell me that
x is> between +/- 2. I know there has got to be an easy way
to do it, but I> can't find it. Any help would
be
appreciated.> Steve Beach> asb4@psu.edu>
http://www.thebeachfamily.org>
====
Bob,Mathematica has
commands to do exactly what you wish and their use is
fairlycommon. The first command is Apply (@@ in
prefix form)
and the secondcommand is Sequence.If you have a list of
arguments such as...arglist = {{a, b}, c, {d, e}, 3, Report
-> True};you can insert them into a function, f, simply by
applying f to the list.f @@ arglistf[{a, b}, c, {d, e}, 3,
Report -> True]If you want to insert them into another
function, h, that also has otherarguments, then you can use
Sequence and Apply.h[firstarg, Sequence @@ arglist, Compile ->
False]h[firstarg, {a, b}, c, {d, e}, 3, Report -> True,
Compile -> False]David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
The problem, of course, is that the output of the Table
command is onebig listand Outer is expecting a sequence
of N separate lists
afterSomeFunction.
====
Bob,KTuples[n_Integer?Positive,
elements_List] := Flatten[Outer[List, Sequence @@
Table[elements, {n}]], n - 1]KTuples[3, {a, b}]{{a, a, a},
{a, a, b}, {a, b, a}, {a, b, b}, {b, a, a}, {b, a, b}, {b, b,
a}, {b, b, b}}Outer produces an array of all the elements but
we have to ßatten it to getit down to a two-level
array.David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
Sender: steve@smc.vnet.netApproved: Steven M. Christensen
, Moderator
====
Raj,You could include
an index for the function in the argument list, or make
aclear separation between parameters and variables as
follows (I just usetwo functions).f[1][r_, t_, p_] := 2r
Sin[t]f[2][r_, t_, p_] := r Cos[t]Sin[p]You could then sum
them, for example, bySum[f[i][r, t, p], {i, 1, 2}]r Cos[t]
Sin[p] + 2 r Sin[t]Or perhaps you wish to sum the derivatives
of the functions with respect tothe second argument,
t.Sum[Derivative[0, 1, 0][f[i]][r, t, p], {i, 1, 2}]2 r
Cos[t] - r Sin[p] Sin[t]Perhaps you can define all your
functions in terms of integer parameters.g[n_, m_][r_, t_,
p_] := r^(m - n)Sin[m t]Cos[n p]You could then sum as
follows.Sum[g[n, m][r, t, p], {m, 1, 3}, {n, 1,
3}]Cos[p]*Sin[t] + (Cos[2*p]*Sin[t])/r +
(Cos[3*p]*Sin[t])/r^2 + r*Cos[p]*Sin[2*t] + Cos[2*p]*Sin[2*t]
+ (Cos[3*p]*Sin[2*t])/r + r^2*Cos[p]*Sin[3*t] +
r*Cos[2*p]*Sin[3*t] + Cos[3*p]*Sin[3*t]Or perhaps you want
to take the square of the derivatives of the functionswith
respect to the first argument, r...Sum[(Derivative[1, 0,
0][g[n, m]][r, t, p])^2, {m, 1, 3}, {n, 1,
3}](Cos[2*p]^2*Sin[t]^2)/r^4 + (4*Cos[3*p]^2*Sin[t]^2)/ r^6 +
Cos[p]^2*Sin[2*t]^2 + (Cos[3*p]^2*Sin[2*t]^2)/ r^4 +
4*r^2*Cos[p]^2*Sin[3*t]^2 + Cos[2*p]^2*Sin[3*t]^2If
possible, try to steer away from For and Do loops and use
functionalprogramming as much as you can. At first it may
seem strange, but it is muchmore powerful and easier once
you get used to it. Ask further questions toMathGroup with
SPECIFIC examples and you will get a lot of help on how
touse functional programming.David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
Sender: steve@smc.vnet.netApproved: Steven M. Christensen
, Moderator
====
David,Except in a few
cases, Mathematica will not automatically generate
theinverse function for you. You will have to Solve the
equations and constructthe inverse function yourself. In
two of your three cases there are actuallymultiple inverse
functions.Taking the easy one first.Clear[x];Solve[f[x] ==
f, x][[1, 1]] // Simplifyx[f_] = x /. %x -> (3 + 2*f)/(1 -
f)(3 + 2*f)/(1 - f)So we now have the inverse
function.x[f](3 + 2*f)/(1 - f)For the quadratic equation
there are two solution.Clear[x]sols = Solve[f[x] == f,
x]{{x -> (1/2)*(7 - Sqrt[9 + 4*f])}, {x -> (1/2)*(7 + Sqrt[9
+ 4*f])}}We define the two solutions and identify them by an
index.x[1][f_] = x /. sols[[1, 1]]x[2][f_] = x /. sols[[2,
1]](1/2)*(7 - Sqrt[9 + 4*f])(1/2)*(7 + Sqrt[9 + 4*f])For the
third example there is a double infinity of
solutions.Clear[x]sols = Solve[f[x] == f,
x]Solve::ifun: Inverse functions are being used by
!(Solve), so some solutions may not be found.{{x
-> -(ArcSin[f]/3)}}Using some trigonometry we can define the
solutions as (I hope I got thisright)Clear[x];x[1,
n_][f_] = (-ArcSin[f] + 2 Pi n)/3x[2, n_][f_] = (-Pi +
ArcSin[f] + 2Pi n)/3Here are some of the solutions for f =
1/2.Table[x[1, n][1/2], {n, -5, 5}]~Join~Table[x[1, n][1/2],
{n, -5, 5}] // Sortf /@ %{-((61*Pi)/18), -((61*Pi)/18),
-((49*Pi)/18), -((49*Pi)/18), -((37*Pi)/18), -((37*Pi)/18),
-((25*Pi)/18), -((25*Pi)/18), -((13*Pi)/18), -((13*Pi)/18),
-(Pi/18), -(Pi/18), (11*Pi)/18, (11*Pi)/18, (23*Pi)/18,
(23*Pi)/18, (35*Pi)/18, (35*Pi)/18, (47*Pi)/18, (47*Pi)/18,
(59*Pi)/18, (59*Pi)/18}{1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2,
1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2, 1/2,
1/2, 1/2, 1/2}Generally, when you want inverse functions you
are going have to do somework.David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
Sender: steve@smc.vnet.netApproved: Steven M. Christensen
, Moderator
====
g[u_, v_] := u -
vg[{x1, y1}, {x2, y2}]{x1 - x2, y1 - y2}David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
y1-y2} but instead one gets error messages.Why ? And how do
I fix g (i.e write a function that outputs thedifference of 2
vectors).
====
>If I have an n-element list, (say where each
element is itself a>list), such as {{a,b}, {a,b}, {a,b}} is
there a way to strip off the>outermost nesting of the list
to obtain just a sequence of of these n>elements, that is
{a,b},{a,b},{a,b} so that I can use this for input>for some
function.Try Sequence@@ as in the
following:In[1]:=x={{a,b},{a,b},{a,b}};In[2]:=g[x_,y_,z_]
:=x(y.z)In[3]:=g[Sequence@@x]Out[3]=!({a ((a^2 +
b^2)), b ((a^2 + b^2))})
====
Why is it that
when I type, say, Table[ Plot[ Sin[n x],{x,0,Pi}], {n,
1,5}]my output is marked in the righthand column with 3 cell
``markers,withthe middle marker encompassing the output
(and *only* the output).However, when I try something like
Table[Show[Graphics[ etc., etc]], {n, 1,5}]the middle cell
marker on the righthand side of the notebook alsoincludes
the input command?The reason that this is important for me
is that I am doing ananimation; and after the animation I
would like to delete all thegraphic images; but when I use
Show[Graphics[ this would mean deletingthe input command as
well.Could someone explain this to me and also make a
suggestion so how Icould use Show[Graphics[ ] and have the
middle cell marker *only*encompass the
output.
====
Bobby,here my solution(s) as promised. As you
stated, my published solution wasonly for rectangles
oriented parallel to the X and Y axis, as this isperhaps
the predominant application.The idea was, to decide whether
all vertices of a rectangle lie to one sideof the other.
This idea expands to the general case. And effectively it
isthe same idea as of your suggestion, as well as of the
improved versionafter Garry Helzer, i.e. the
constructive solutions, as opposed to thoseinvolving
more abstract mathematical reasoning as of David Park and
AndrzejKozlowski. And these, esp. Andrzej's, are very
interesting, as they show howto derive a solution just
from this kind of reasoning.First some preliminaries: random
rectanglesI had chosen to describe the rectangles as a list
of counterclockwisevertices. To generate them, I had used a
similar description as David Park:toRectangle[corner_,
[Theta]_, base_, side_] := Module[{vb = {Cos[[Theta]],
Sin[[Theta]]}* base, vs = {-Sin[[Theta]],
Cos[[Theta]]}* side}, {corner, corner + vb, corner + vb +
vs, corner + vs}]makeRect[] := toRectangle[{Random[],
Random[]}, [Pi]/2 Random[], Random[],
Random[]]rectLine[{pFirst_, pRest__}] := Line[{pFirst,
pRest, pFirst}]ShowRects[r1_, r2_] :=
Show[Graphics[{PointSize[0.05], Hue[.5], rectLine[r1],
MapIndexed[{Point[#1], GrayLevel[0], Text[First[#2], #1]} &,
r1], Hue[0], rectLine[r2], MapIndexed[{Point[#1],
GrayLevel[0], Text[First[#2], #1]} &, r2]}], Background ->
GrayLevel[.8], AspectRatio -> Automatic, PlotRange ->
All]test cases:rect[1] = toRectangle[{0, 0}, 0, 1, 1]; (*
from David *)rect[2] = toRectangle[{1, 1}*0.9, [Pi]/4, 2,
1];ShowRects[rect[1], rect[2]]rx = rect[2] /. {x_?NumericQ,
y_} :> {x, y} + {-0.1, 0.15};ShowRects[rect[1], rx]rxx =
{{-.5, .2}, {1.5, .2}, {1.5, .8}, {-.5,
.8}};ShowRects[rect[1], rxx]test data:recs1000 =
Table[makeRect[],{1000}];Now here my solution. It is written
such as to communicate the idea, call
itelegant:offSide[r2_][{p1_, p2_}] := And @@ ((p2 - p1).(#
- p1) <= 0 &) /@ r2rectOverlap[r1_, r2_] := =AC (Or @@
offSide[r2] /@ Partition[r1, 2, 1, {1, 1}] [Or] Or @@
offSide[r1] /@ Partition[r2, 2, 1, {1, 1}])I came to this,
when I tried to expand my solution for evenly
orientedrectangles to the general case. I first tried
oblique coordinates, sightingalong the sides of the
rectangles, then saw that giving them in the dualbase is
computationally simpler, to recognize i.e. just the distance
of apoint from the side's (straight
line).Correctness:rectOverlap[rect[1],
rect[2]]TruerectOverlap[rect[1],
rx]FalserectOverlap[rect[1],
rxx]TruePerformance:(testr1 = MapThread[ rectOverlap,
{recs1000, RotateLeft[recs1000, 1]}]); // Timing{3.635
Second, Null}The costs for RotateLeft are negligable in
Timing.Garry Helzer had proposed a solution which wasn't
correct (e.g. for rect[1},rxx) as he noted himself. Bobby
Treat however noticed that it can be fixed.Here my version
thereof. (You can see how similar it is, starting
fromdifferent reasoning.)rightSide[a_, {b_, c_}] :=
Det[Prepend[#, 1] & /@ {a, b, c}] < 0vertexExcluded[r1_,
r2_] := =AC (Or @@ And @@@ Outer[rightSide[#2, #1] &,
Partition[r2, 2, 1, {1, 1}], r1, 1] [Or] Or @@ And @@@
Outer[rightSide[#2, #1] &, Partition[r1, 2, 1, {1, 1}], r2,
1])(testr4 = MapThread[ vertexExcluded, {recs1000,
RotateLeft[recs1000, 1]}]); // Timing{3.646 Second,
Null}testr1 === testr4Trueof quite similar
performance.Bobby Treat gave a different implementation of
this (as seen below) which ismarginally faster.Now here
Bobby's solution, rewritten in my style (which makes it
slightlyfaster):extent[r1_, r2_] := {Min[#], Max[#]} & /@
((r1[[{1, 2}]] - r1[[{2,
3}]]).Transpose[r2])cannotIntersect[{{min1_, max1_}, {min2_,
max2_}}] := max2 < min1 || max1 < min2intersects[r1_, r2_] :=
Catch[If[cannotIntersect[#], Throw[False]] & /@
Flatten[Transpose[ Join[Outer[extent, {r1}, {r1, r2}, 1],
Outer[extent, {r2}, {r2, r1}, 1]], {1, 3, 2}], 1];
True](testr5 = MapThread[intersects, {recs1000,
RotateLeft[recs1000, 1]}]); //Timing{1.502 Second,
Null}testr5 === testr1Truethe tests for all sides. Such
we come to use of the non-strict evaluation ofAnd[ ] and
Or[ ]. This effectively corresponds to a Catch and
Throw.rectOverlap2[r1 : {p1_, p2_, p3_, p4_}, r2 : {q1_,
q2_, q3_, q4_}] :=! Or[ ((p2 - p1).(# - p1) <= 0 &) /@ And @@
r2, ((p3 - p2).(# - p2) <= 0 &) /@ And @@ r2, ((p4 - p3).(# -
p3) <= 0 &) /@ And @@ r2, ((p1 - p4).(# - p4) <= 0 &) /@ And
@@ r2, ((q2 - q1).(# - q1) <= 0 &) /@ And @@ r1, ((q3 -
q2).(# - q2) <= 0 &) /@ And @@ r1, ((q4 - q3).(# - q3) <= 0
&) /@ And @@ r1, ((q1 - q4).(# - q4) <= 0 &) /@ And @@
r1](testr2 = MapThread[ rectOverlap2, {recs1000,
RotateLeft[recs1000, 1]}]); // Timing{1.502 Second,
Null}testr2 === testr1TrueEqual in performance to Bobby's
solution. The use of And with ((p2 - p1).(#- p1) <= 0 &) /@
And @@ r2, etc. is a bit tricky: it effectively preventsthe
evaluation of (p2 - p1).(q1 - p1) <= 0 etc., such that this is
evaluatedwithin And (non-standard evaluation) after
mapping. And @@ ((p2 - p1).(# -p1) <= 0 &) /@ r2 to the
contrary is less performant. (You can see here howclever
the language is designed, to allow use of And as a container,
untilthe time comes to execute!)This solution can be
improved a little bit; we replace mapping by threadingand
delay execution of the pure functions' body to the
application of Andnow by a different method (since we don't
Map):rectOverlap3[r1 : {p1_, p2_, p3_, p4_}, r2 : {q1_, q2_,
q3_, q4_}] :=! Or[ Block[{v = p2 - p1}, Or[And @@
Thread[Unevaluated[(Unevaluated[v.(# - p1) <= 0] &)[r2]]],
And @@ Thread[Unevaluated[(Unevaluated[v.(# - p2) >=
0]&)[r2]]]]], Block[{v = p4 - p1}, Or[And @@
Thread[Unevaluated[(Unevaluated[v.(# - p1) <= 0] &)[r2]]],
And @@ Thread[Unevaluated[(Unevaluated[v.(# - p4) >=
0]&)[r2]]]]], Block[{v = q2 - q1}, Or[And @@
Thread[Unevaluated[(Unevaluated[v.(# - q1) <= 0] &)[r1]]],
And @@ Thread[Unevaluated[(Unevaluated[v.(# - q2) >=
0]&)[r1]]]]], Block[{v = q4 - q1}, Or[And @@
Thread[Unevaluated[(Unevaluated[v.(# - q1) <= 0] &)[r1]]],
And @@ Thread[Unevaluated[(Unevaluated[v.(# - q4) >=
0]&)[r1]]]]]](testr3 = MapThread[ rectOverlap3, {recs1000,
RotateLeft[recs1000, 1]}]); // Timing{1.442 Second,
Null}testr3 === testr1TrueSo this is fastest by a small
margin, but has lost almost all elegance. Theouter
Unevaluated is necessary to prevent evaluation within Thread,
theinner does the essential trick noted above.Hope this was
of some interest,Hartmut>-----Original Message----->Sent:
Monday, August 26, 2002 10:16 AM> rectangle
intersection>Garry,>>Also note your solution requires
rectangle points to be in clockwise>order (mine doesn't),
but yours works for arbitrary convex polygons
as>written.>>Bobby>>-----Original Message----->RE:
>rectangle intersection>>Garry,>>Here's a solution using
your LeftSide concept; it works perfectly but>takes twice
as much time as my solution. Both solutions look at
every>vertex of both rectangles, but mine uses two sides
from each and yours>requires looking at all four sides of
each rectangle. I'd think yours>should be a triße faster
than this, though. There may be efficiencies>I'm
missing (in
both solutions).>>ClearAll[cis, rect, pickRect, extent,
cannotIntersect, intersects,>daveRect]>cis[t_] := {Cos@t,
Sin@t}>rect[{pt : {_, _}, angle_, {len1_, len2_}}] :=
Module[{pt2},> {pt, pt2 => pt + len1 cis[angle],> pt2 - len2
cis[angle - Pi/2], pt - len2 cis[angle - Pi/2]}]>daveRect :=
{{Random[], Random[]}, Random[] + Pi/2,
{Random[],>Random[]}}>pickRect := rect@daveRect>extent[r1_,>
r2_] := {Min@#, Max@#} & /@ ((Take[r1, 2] -
r1[[{2,>3}]]).Transpose@r2)>cannotIntersect[{{min1_, max1_},
{min2_,> max2_}}] := max2 < min1 || min2 >
max1>intersects[r1_, r2_] := Catch[> If[cannotIntersect[#],
Throw[False]] & /@>Flatten[Transpose[Outer[extent, >{r1},
{r1, r2}, 1]~Join~Outer[extent, {r2}, {r2, r1}, 1], {1, 3,
2}],>1];>
Throw[True]]>>ClearAll[leftSide,leftIntersects,sides]>sides[a
_List]:=Partition[Join[a,{First@a}],2,1]>leftSide[{a_,b_},{{c
_,d_},{e_,f_}}]:=-b c+a d+b e-d e-a f+c
f>0>leftSide[a:{{_,_}..},b:{{_,_},{_,_}}]:=leftSide[#,b]&/@a
>leftSide[a_List,b:{{{_,_},{_,_}}..}]:=leftSide[a,#]&/@b>
leftIntersects[a_,b_]:=!Or@@(And@@#&/@leftSide[a,sides@b])&&!
>
Or@@(And@@#&/@leftSide[b,sides@a])>>davePairs={daveRect,
daveRect}&/@Range[10000];>rectanglePairs=Map[Reverse@rect[#]&
,davePairs,{2}];>Timing[right=intersects[Sequence@@#]&/@
rectanglePairs;]>Timing[test=leftIntersects[Sequence@@#]&/@
rectanglePairs;]>right[Equal]test>>{3.187999999999999*
Second, Null}>{6.765000000000001*Second, Null}>True>>Bobby
Treat>>-----Original Message----->
rectangle>intersection>>As Daniel Lichtblau pointed out,
the statement below about vertices is >nonsense. Consider two
overlapping rectangles arranged as a cross. You >need to
compute intersections and test them instead of
vertices.>>Begin forwarded message:>>
rectangle>intersection>> Begin forwarded message:>>
Dear colleagues,>> any hints on how to implement a very
fast routine in Mathematica for>> testing if two rectangles
have an intersection area?>> Frank Brand>> Here is one
approach.>> Given three points {x1,y1},{x2,y2},{x3,y3},
switch to homogenous>> coordinates a={1,x1,y1}, b={1,x2,y2},
c={1,x3,y3}. Then>> Sign[Det[{a,b,c}]] is +1 if and only if
the point a lies on your left>as>> you walk along the line
though b and c in the direction from b to c.>> ( If the
result is zero, then a lies on the line.)>> The value of
the determinant is>x2y3-x3y2-x1y3+x3y1+x1y2-x2y1, and the>>
speed of the algorithm depends essentially on how fast this
quantity>can>> be computed. Suppose we write a function
LeftSide[a,{b,c}] that>computes>> the sign of the
determinant.>> Now let {p1,p2, . . ., pn} be a list of
vertices (pi={xi,yi}) of a>> convex polygon traced
counterclockwise. Then a lies within or on the>> boundary of
the polygon if and only if none of the numbers>>
LeftSide[a,{pi,p(i+1)}] are -1. That is, if -1 does not
appear in the>> list LeftSide[a,#]&/@Partition[{p1,p2,. .
.,pn,p1},2,1].>> Now use the fact that if two convex
polynomials overlap, then some>> vertex of one of them must
lie inside or on the boundary of>the other.>> If an
overlap of positive area is required, then the check is
that>only>> +1 appears--not that -1 does not appear.>>
For two rectangles ( or parallelograms) this approach
requires the>> evaluation of 16 determinants, so it may be a
bit expensive. If the>> points have rational coordinates,
then (positive) denominators may be>> cleared in the
homogeneous coordinates and the computations can be>done>>
in integer arithmetic, at the cost of at least three more>>
multiplications per determinant.>Garry Helzer>Department
of Mathematics>University of Maryland>College Park, MD
20742>301-405-5176>gah@math.umd.edu>
====
I'm
looking for a way of finding the approximation for partitial
binomial sum.I'll be pleasant for any
hint..Constantine.Constantine ElsterComputer Science
Dept.Technion I.I.T.Office: Taub 411
====
> Here's my
contestant:> <
KTuples[k_Integer, vals_List] :=>
Union[KSubsets[PadRight[vals, k*Length[vals], vals], k]]Dear
mathgroup,Here is another solution; probably less elegant,
but I found it much faster (DiscreteMath's Subsets and
KSubsets are too slow. Besides, it produces each tuple only
once):KTuples2[n_Integer, L_List] := Flatten[Outer[Append,
KTuples2[n-1, L], L, 1], 1] /; n > 1;KTuples2[1, L_List] :=
Transpose[{L}](Both function yields the tuples in
lexicographic order.)Sz. Szikla
====
Here a easy way
:In[4]:=expr=a b x^2 + 5 x^3 + 5 Sqrt[4 -
x^2]In[5]:=FullForm[expr]Out[5]//FullForm=Plus[Times[a,b,
Power[x,2]],Times[5,Power[x,3]],
Times[5,Power[Plus[4,Times[-1,Power[x,2]]],Rational[1,2]]]]
In[9]:=expr[[3,2,1]]Out[9]=4 - x^2Meilleures
salutationsFlorian Jaccardprofesseur de
Math.8ematiquesEICN-HES-----Message
d'origine-----Envoy.8e : mar., 27. ao.9et 2002 08:08è
:
mathgroup@smc.vnet.netObjet : How do I pick out the
expression under a radical?I'm a poor physicist trying to
figure out how to sort out thephysical from the
non-physical solutions to a problem. To dothat, I need
to be able to look at an expression and pick out
asubexpression, the part under the radical.For example,
say I've got the expressiona b x^2 + 5 x^3 + 5 Sqrt[4 -
x^2]I'd like to pick out 4 - x^2, which would then tell me
that x isbetween +/- 2. I know there has got to be an easy
way to do it, but Ican't find it. Any help would
be
appreciated.Steve
Beachasb4@psu.eduhttp://www.thebeachfamily.org
====
> I'm
a poor physicist trying to figure out how to sort out the>
physical from the non-physical solutions to a problem.
To do> that, I need to be able to look at an expression and
pick out a> subexpression, the part under the radical.>> For
example, say I've got the expression>> a b x^2 + 5 x^3 + 5
Sqrt[4 - x^2]>> I'd like to pick out 4 - x^2, which would
then tell me that x is> between +/- 2. I know there has got
to be an easy way to do it, but I> can't find
it.>Needs[Algebra`InequalitySolve`];expr = a b x^2+5
x^3+5 Sqrt[4-x^2];InequalitySolve[#>=0, x]& /@ Cases[expr,
Sqrt[x_] -> x, Infinity]{-2 <= x <= 2}Bob HanlonChantilly,
VA USA
====
> I would like to know, if is possible to solve>
> Integrate[(exp[-a/x])/(x^2-b^2),{x,0,infinity}] with> a
and b constant ( Real )> using Mathematica.>
Integrate[(Exp[-a/x])/(x^2-b^2),{x,0,Infinity},
GenerateConditions->False]//FullSimplifySqrt[-(1/b^2)]*((1/
2)*Pi*Cosh[a/b] +
CosIntegral[a*Sqrt[-(1/b^2)]]*Sin[a*Sqrt[-(1/b^2)]]) +
(Cosh[a/b]*SinhIntegral[a/b])/bFullSimplify[%,
Element[{a,b},
Reals]](1/(2*b*Abs[b]))*(-2*b*CosIntegral[(I*a)/Abs[b]]*
Sinh[a/Abs[b]] + Cosh[a/b]*(I*b*Pi +
2*Abs[b]*SinhIntegral[a/b]))Bob HanlonChantilly, VA
USA
====
Bob,Table[ Plot[ Sin[n x], {x, 0, Pi}], {n, 1,
5}]andTable[ Show[Graphics[Line[{{0, 0}, {5, n}}]],
PlotRange -> {{0, 6}, {0, 6}}], {n, 1, 5}]They both have the
graphics output cells grouped in the middle and separatefrom
the Input cell.David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
The reason that this is important for me is that I am doing
ananimation; and after the animation I would like to delete
all thegraphic images; but when I use Show[Graphics[ this
would mean deletingthe input command as well.Could someone
explain this to me and also make a suggestion so how Icould
use Show[Graphics[ ] and have the middle cell marker
*only*encompass the output.
====
Steve,Here is a slightly
more complicated case.expr = a b x^2 + 5 x^3 + 5 Sqrt[4 -
x^2] - 1/Sqrt[5 - 2x^2]The following picks out the
expressions under square roots. Square roots
arerepresented as Power[a,1/2] and if they are in the
denominator they area -1/2 power. We use an Alternative in
the pattern to pick out both.rexprs = Cases[expr, Power[a_,
1/2 | -1/2] -> a, Infinity]{5 - 2*x^2, 4 - x^2}The following
Standard Package is
useful.Needs[Algebra`InequalitySolve`]And @@ (# >= 0 &
/@ rexprs)InequalitySolve[%, x]5 - 2*x^2 >= 0 && 4 - x^2 >=
0-Sqrt[5/2] <= x <= Sqrt[5/2]David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
Steve
Beachasb4@psu.eduhttp://www.thebeachfamily.org
====
Valdeci,It appears that the integral will not converge if b
is real. Mathematicagives...Integrate[Exp[-a/x]/(x^2 -
b^2), {x, 0, Infinity}]If[Re[a] > 0 && Arg[b^2] != 0,
(1/2)*Sqrt[-(1/b^2)]* (2*CosIntegral[a*Sqrt[-(1/b^2)]]*
Sin[a*Sqrt[-(1/b^2)]] + Cos[a*Sqrt[-(1/b^2)]]* (Pi -
2*SinIntegral[a*Sqrt[-(1/b^2)]])), Integrate[1/(E^(a/x)*(-b^2
+ x^2)), {x, 0, Infinity}]]If b is Real then Arg[b^2]==0 and
Mathematica doesn't solve it. Let's
definea function that
allows us to test specific values of a and b.f[a_, b_][x_] =
Exp[-a/x]/(x^2 - b^2);Integrate[f[2, 3][x], {x, 0,
Infinity}]Integrate::idiv : Integral of 1/(E^(2/x)*(-9 +
x^2)) does not converge on{0, Infinity}.But if we use an
imaginary value for b...Integrate[f[2, 3I][x], {x, 0,
Infinity}]%//N(1/6)*(2*CosIntegral[2/3]*Sin[2/3] +
Cos[2/3]*(Pi - 2*SinIntegral[2/3]))0.254022David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
MasterÇs Degree of Applied Physics - Unesp/Rio Claro -
State
of S.8boPaulo - BrazilLaboratory of Electrical
Measurementsphone : ( 0XX19 ) 526 -
2237*********************************************************
************
====
I am having a strange problem with a
function giving a complex number as a result. I did the
following:- define a function:denom[x_, p_, d_] := Sqrt[1 +
(x*Tan[p]/d)^2]Integrate and simplify it with the assumption
that d is larger than 0:FullSimplify[Integrate[denom[x, p,
d], {x, 0, d}], d > 0]The result of the above line is
d/2*(1+i*Sqrt[2]*d*Cos[p]^2)*Sqrt[Sec[p]^2] where i is
Sqrt[-1]I assing it to a function called peter in the
following way:peter[p_, d_] :=
FullSimplify[Integrate[denom[x, p, d], {x, 0, d}], d>0]and
check the value of the function at [0,1]peter[0,1]and the
result is 1.How is it possible that the result doesn't have
an imaginary part???I would expect the result to be
0.5+Sqrt[2]/2*iPeter
====
Lucas,One way to change the
precedence of CirclePlus is to change the
fileUnicodeCharacters.tr.On my machine the file is
located
under../4.1/SystemFiles/FrontEnd/TextResourcesOpen up the
file, search for CirclePlus, change the precedence from 450
to420, and then save. Of course, it would be wise to make a
backup copy of thefile before you make any changes. Also,
420 is low enough to get thebehavior you desire, but you
may want to experiment with other precedences.Then, start
mathematica and you will get the behavior you want.Carl
WollPhysics DeptU of Washington>> I'm attempting to
implement an abstract mathematica package in> mathematica
that utilized the [CirclePlus] operator in an unusual>
way. Specifically, the [CirclePlus] has a precidence lower
than +> and introduces barriers in the computation. So, an
expression such as>> a + b [CirclePlus] c + d --> (a+b)
[CirclePlus] (c+d)>> The mathematica ouput of>> a + d + (b
[CirclePlus] c) is incorrect. I've tried playing with the>
PrecedenceForm[] function, but that does not seem able to
produce the> desired effect.>> Also, I would like to
introduce a notation like>> N> [BigCirclePlus] x[[i]] -->
x[[1]] [CirclePlus] x[[2]] [CirclePlus]> ....> i=0>>
analagous to summation, but mathematica does not appear to
offer the> CirclePlus in a large format. to relate this to
the case above, x[1]> = (a + b) and> x[2] = (c + d), so each
indexed element is a subexpression.>> Finally, I would like to
be able to set up the CirclePlus operator> such that the
following algebraic relations hold:> Sum BigCirclePlus
E = BigCirclePlus Sum E> i j ij j i ij>> d d> --
BigCirclePlus E = BigCirclePlus -- E> dx j j j dx j>>
-Lucas Scharenbroich> -MLS Group / JPL>
====
Lucas,I hope
that your question will provoke a number of replies because I
thinkit is an interesting topic.First, it would be nice if
Mathematica had a ShowPrecedence statement toquickly
retrieve a precedence number for any command. It is a bit
timeconsuming to search through the table in Section
A.2.7.Next, it would be nice if the user could set the
precedence for operatorsthat don't have built-in
definitions.Since it appears that you can't do
that, is it
possible to switch themeanings of Plus and CirclePlus in
your theory? Are you depending on thenumerical behavior of
Plus? Go with the precedence that Mathematica givesyou. Or
you could use something like VerticalBar or RightTee which
havelower precedence than Plus, but perhaps don't have the
look that you want.You could try to use the Notation package
for your CirclePlus sum. But Ialways find the Notation
package difficult to use and like to useStandardForm as much
as possible. One possibility is...!((([Sum]+(i =
1)%5 x[i])) /. Plus -> CirclePlus)These are weak
answers to your question, but maybe they will bring in
morediscussion.David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
desired effect.Also, I would like to introduce a notation
like N[BigCirclePlus] x[[i]] --> x[[1]] [CirclePlus]
x[[2]] [CirclePlus].... i=0analagous to summation, but
mathematica does not appear to offer theCirclePlus in a
large format. to relate this to the case above, x[1]= (a + b)
andx[2] = (c + d), so each indexed element is a
subexpression.Finally, I would like to be able to set up the
CirclePlus operatorsuch that the following algebraic
relations hold:Sum BigCirclePlus E = BigCirclePlus
Sum E i j ij j i ijd d-- BigCirclePlus E =
BigCirclePlus -- Edx j j j dx j-Lucas Scharenbroich-MLS
Group / JPL
====
I need some help with using FindRoot. I want
to solve a system ofnonlinear equations numerically. Each
equation in the system is anequation with vector variables.
The equations are such that it isdifficult to convert them to
equations involving only the componentsof the vector
variables.I have tried the following two possibilities
without success. In whatfollows I am using a MADE UP
EXAMPLE. In this example it is easy towrite the equations
in terms of only the components. Furthermore thecorrect
solution is obvious. But I made up the example
forillustration
only.----------------------------Try1-----------------------
---------------------q = {{x[1], y[1]}, {x[2],
y[2]}};FindRoot[{q[[1]] + q[[2]] Sqrt[q[[2]].q[[2]]] == {0,
0}, q[[1]] + q[[2]] == {0, 0}}, {q[[1]], {0, 0}}, {q[[2]],
{0, 0}}]This results in the error message
:FindRoot::fddis: Start specification {q[[1]],{0,0}} does
not containdistinctstarting
values.----------------------------Try2---------------------
------------------------FindRoot[{q[[1]] + q[[2]]
Sqrt[q[[2]].q[[2]]] == {0, 0}, q[[1]] + q[[2]] == {0, 0}},
{x[1], 0}, {x[2], 0}, {y[1], 0},{y[2], 0}]This results in
the error message :FindRoot::frnum: Function
{0.,0.},{0.,0.}} is not a length 4 listof numbers at
{x[1],x[2],y[1],y[2]} = {0., 0., 0., 0.}Questions 1) How do
I fix these two methods ? 2) What do the error messages mean
?Please keep in mind that this example is made up and
trivial to solvewithout Mathematica. It is being used for
illustration purpose only.
====
> I need some help with using
FindRoot. I want to solve a system of> nonlinear equations
numerically. Each equation in the system is an> equation
with vector variables. The equations are such that it is>
difficult to convert them to equations involving only the
components> of the vector variables.> I have tried the
following two possibilities without success. In what>
follows I am using a MADE UP EXAMPLE. In this example it is
easy to> write the equations in terms of only the
components. Furthermore the> correct solution is obvious.
But I made up the example for> illustration only.>
----------------------------Try>
1--------------------------------------------> q = {{x[1],
y[1]}, {x[2], y[2]}};> FindRoot[{q[[1]] + q[[2]]
Sqrt[q[[2]].q[[2]]] == {0, 0}, > q[[1]] + q[[2]] == {0, 0}},
{q[[1]], {0, 0}}, {q[[2]], {0, 0}}]> This results in the
error message :> FindRoot::fddis: Start specification
{q[[1]],{0,0}} does not contain> distinct> starting
values.> ----------------------------Try>
2--------------------------------------------->
FindRoot[{q[[1]] + q[[2]] Sqrt[q[[2]].q[[2]]] == {0, 0}, >
q[[1]] + q[[2]] == {0, 0}}, {x[1], 0}, {x[2], 0}, {y[1], 0},>
{y[2], 0}]> This results in the error message :>
FindRoot::frnum: Function {0.,0.},{0.,0.}} is not a
length 4 list> of numbers at {x[1],x[2],y[1],y[2]} = {0.,
0., 0., 0.}> Questions > 1) How do I fix these two methods
? For the second, you can ...o Make sure the first argument
is evaluated (use Evaluate[])o Get rid of the Equal (==)o
Flatten the
vectors.In[1]:=q={{x[1],y[1]},{x[2],y[2]}};FindRoot[
Evaluate[ Flatten[{q[[1]]+q[[2]]
Sqrt[q[[2]].q[[2]]],q[[1]]+q[[2]]}]],{x[1],
0},{x[2],0},{y[1],0},{y[2],0}]Out[2]={x[1] -> 0., x[2] ->
0., y[1] -> 0., y[2] -> 0.}For the first, you will have to
wait until a future version of Mathematica (this works in a
development version now as shown below) which will support
vector variables. It will still not support variables with
head Part (like q[[1]]), so you can doFindRoot[{q1 + q2
Sqrt[q2.q2], q1 + q2},{q1,{0,0}},{q2,{0,0}}]which
returnsIn[1]:=FindRoot[{q1 + q2 Sqrt[q2.q2], q1 +
q2},{q1,{0,0}},{q2,{0,0}}]Out[4]=Note that the Evaluate[]
will no longer be necessary> 2) What do the error messages
mean ?FindRoot::fddis: means FindRoot is looking for
numbers as starting values.FindRoot has a syntax which
accepts two starting values for using
derivativeFindRoot::frnum: If FindRoot cannot resolve a
list of equalities, it looks fora list of something which
evaluates to numbers when the variables take on numerical
values.> Please keep in mind that this example is made up
and trivial to solve> without Mathematica. It is being used
for illustration purpose only.>
====
If I want to protect
the Mathematica Program, what can I do? Is there any method
to avoid other people's reading my program butit is still
able to run ßuently? Gory
====
You could try obfuscating it,
i.e., scrambling the symbol namesexcept for those you wish
to export.Check out obfuscation tools
underhttp://www.semdesigns.com/Products/Formatters/
index.html.We don't have an obfuscator at this moment for
Mathematica,but our base technology can build obfuscators
for langaugesfor which we have definitions, ... and we
happen to havea definition of Mathematica.--Ira Baxter,
Ph.D. CTO Semantic Designswww.semdesigns.com 512-250-1018>
If I want to protect the Mathematica Program, what can I do?
Is there anymethod to avoid other people's reading my
program but> it is still able to run ßuently?>
Gory>
====
Mathematica version 4.2 has no problem with this
one. All you have todo is spell things
correctly.Integrate[Exp[-a/x]/(x^2 - b^2), {x, 0,
Infinity}]If[Re[a] > 0 && Arg[b^2] != 0,
(1/2)*Sqrt[-(1/b^2)]* (2*CosIntegral[ a*Sqrt[-(1/b^2)]]*
Sin[a*Sqrt[-(1/b^2)]] + Cos[a*Sqrt[-(1/b^2)]]* (Pi -
2*SinIntegral[ a*Sqrt[-(1/b^2)]])), Integrate[1/(E^(a/x)*
(-b^2 + x^2)), {x, 0, Infinity}]]Bobby Treat-----Original
Message-----*************************************************
********************Valdeci Mariano de SouzaMasterÇs
Degree of Applied Physics - Unesp/Rio Claro - State of
S.8boPaulo - BrazilLaboratory of Electrical
Measurementsphone : ( 0XX19 ) 526 -
2237*********************************************************
************
====
FullForm[expr]Plus[Times[a,b,Power[x,2]],
Times[5,Power[x,3]],
Times[5,Power[Plus[4,Times[-1,Power[x,2]]],Rational[1,2]]]]
What you want is the third argument of Plus, the second
argument ofTimes, and the first argument of Power.expr = a
b x^2 + 5 x^3 + 5 Sqrt[4 - x^2];expr[[3]]expr[[3,
2]]expr[[3, 2, 1]]5*Sqrt[4 - x^2]Sqrt[4 - x^2]4 - x^2Bobby
Treat-----Original Message-----can't find it.
Any help would
be appreciated.Steve
Beachasb4@psu.eduhttp://www.thebeachfamily.org
====
I try
to do the simple task of transposing a matrix.X =
{{a,b},{c,d},{e,f}}whereas Transpose[{{a,b},{c,d},{e,f}}]
works well.What is wrong with writing Transpose[X] ?Terje
Johnsen
====
>-----Original Message----->Sent: Monday, August
26, 2002 10:16 AM>Lucas,>>I hope that your question will
provoke a number of replies >because I think>it is an
interesting topic.>>First, it would be nice if Mathematica
had a ShowPrecedence >statement to>quickly retrieve a
precedence number for any command. It is a bit
time>consuming to search through the table in Section
A.2.7.>>Next, it would be nice if the user could set the
precedence >for operators>that don't have built-in
definitions.>>Since it appears that you can't do
that, is it
possible to switch the>meanings of Plus and CirclePlus in
your theory? Are you >depending on the>numerical behavior of
Plus? Go with the precedence that >Mathematica gives>you. Or
you could use something like VerticalBar or RightTee which
have>lower precedence than Plus, but perhaps don't have the
look >that you want.>>You could try to use the Notation
package for your CirclePlus >sum. But I>always find the
Notation package difficult to use and like to
use>StandardForm as much as possible. One possibility
is...>>!((([Sum]+(i = 1)%5 x[i])) /. Plus
-> CirclePlus)>>These are weak answers to your question,
but maybe they will >bring in more>discussion.>>David
Park>djmp@earthlink.net>http://home.earthlink.net/~djmp/>
>I'm attempting to implement an abstract mathematica
package in>mathematica that utilized the [CirclePlus]
operator in an unusual>way. Specifically, the [CirclePlus]
has a precidence lower than +>and introduces barriers in the
computation. So, an expression such as>>a + b [CirclePlus]
c + d --> (a+b) [CirclePlus] (c+d)>>The mathematica ouput
of>>a + d + (b [CirclePlus] c) is incorrect. I've tried
playing with the>PrecedenceForm[] function, but that does
not seem able to produce the>desired effect.>>Also, I would
like to introduce a notation like>> N>[BigCirclePlus]
x[[i]] --> x[[1]] [CirclePlus] x[[2]] [CirclePlus]>....>
i=0>>analagous to summation, but mathematica does not appear
to offer the>CirclePlus in a large format. to relate this to
the case above, x[1]>= (a + b) and>x[2] = (c + d), so each
indexed element is a subexpression.>>Finally, I would like to
be able to set up the CirclePlus operator>such that the
following algebraic relations hold:>Sum BigCirclePlus E
= BigCirclePlus Sum E> i j ij j i ij>>d d>--
BigCirclePlus E = BigCirclePlus -- E>dx j j j dx
j>>-Lucas Scharenbroich>-MLS Group / JPL>Lucas,I'm
certainly not competent to give you any answer, and me too,
I'd be eagerto hear such -- hoped Wolfram's to
react;
anyway, here is my opinion.PrecedenceForm is only for
parenthesizing at output.Although we have MakeExpressions to
add semantic actions to the Mathematicacompiler (if we may
call such the transformation from input string,
i.e.language, to the internal representation as indicated
by FullForm i.e.code), we cannot inßuence the Mathematica
syntax proper, i.e. parsing.The operator precedence rules
however are part of that (esp. needed for boxformation). So
I can't see a way to reach your goal. Now, I
don't know what
your ordinary Plus shall designate. If it's onlyabstract,
i.e. you don't use it for numeric calculation, you possibly
mightinterchange the roles of Plus and CirclePlusIn[6]:=
a [CirclePlus] b + c [CirclePlus] dOut[6]=
a[CirclePlus]b + c[CirclePlus]dAs for BigCirclePlus (if
you still need it after the reassigned meanings)I'd try to
define a palette, but perhaps this is not possible to the
extendyou desire. I never tried.Another approach would be
to use Union and Intersection for low precedenceplus and
low precedence times (or [Subset]; [Superset] or
[And]; [Or]or [Therefore];[Because] or ...).The
ultima ratio is to write a new front end.But, if I were you,
I'd ignore these kind of problems at first and
set upthe
package fully functioning (with 1D input), apply it to your
problems andinvestigations, and finally, when time comes to
publishing, at outputformatting you have quite a lot of
choices.I'm sorry, just wanted to keep the discussion alive,
since anyway, this isof much interest.--Hartmut
====
>
Lucas,> I'm certainly not competent to give you any answer,
and me too, I'd be eager> to hear such -- hoped
Wolfram's to
react; anyway, here is my opinion.> PrecedenceForm is only
for parenthesizing at output.> Although we have
MakeExpressions to add semantic actions to the Mathematica>
compiler (if we may call such the transformation from input
string, i.e.> language, to the internal representation as
indicated by FullForm i.e.> code), we cannot inßuence the
Mathematica syntax proper, i.e. parsing.> The operator
precedence rules however are part of that (esp. needed for
box> formation). So I can't see a way to reach your goal. >
> Now, I don't know what your ordinary Plus shall designate.
If it's only> abstract, i.e. you don't use it
for numeric
calculation, you possibly might> interchange the roles of
Plus and CirclePlus> In[6]:= a [CirclePlus] b + c
[CirclePlus] d> Out[6]= a[CirclePlus]b +
c[CirclePlus]d> As for BigCirclePlus (if you still need
it after the reassigned meanings)> I'd try to
define a
palette, but perhaps this is not possible to the extend>
you desire. I never tried.> Another approach would be to
use Union and Intersection for low precedence> plus and
low precedence times (or [Subset]; [Superset] or
[And]; [Or]> or [Therefore];[Because] or ...).>
The ultima ratio is to write a new front end.> But, if I
were you, I'd ignore these kind of problems at
first and set
up> the package fully functioning (with 1D input), apply it
to your problems and> investigations, and finally, when time
comes to publishing, at output> formatting you have quite a
lot of choices.> I'm sorry, just wanted to keep the
discussion alive, since anyway, this is> of much
interest.is actually quite simple -- just a list of
expressions. If I had anappropriate OutputForm written then
the effect would be:{expr1, expr2, ..., exprN} --> expr1
[CirclePlus] expr2 [CirclePlus]...So certainly I cn get
a functional package, but the final productshould be
notationally similar to the pure mathematical reference. I'm
sure this is a goal shared by many.If anyone is curious about
what exactly I'm up to, I'm attempting
toimplement a Clocked
Objective Function package based (primarily) onthese
publications:A Lagrangian Formulation of Neural Networks I:
Theory and AnalogDynamicsA Lagrangian Formulation of
Neural Networks II: Clocked ObjectiveFunctions and
ApplicationsBoth are found in Neural, Parallel and
Scientific Computations 6(1998) 297-372, authors are Eric
Mjolsness and Willard L. Miranker-Lucas Scharenbroich-JPL /
MLS Group
====
> I am writing a Java application that displays
Mathematica output using > MathCanvas. I am having difficulty
in that the internal frames > (JInternalFrame)in my
application are covered by the MathCanvas when > the
internal frames are moved into the MathCanvas area. I tried
> setting the frame's layer to 0, but that
didn't work. Can
anyone help > me out?I suppose the problem is, that
MathCanvas is an AWT Component, whichcauses problem with
the other Swing JComponents;2 possible solutions: - get
J/Link 2.0, which comes with a Swing version of
MathCanvas(MathGraphicsJPanel if memory serves); - if you
can't do that, write a Swing replacement for
MathCanvasusing Swing; this is pretty simple: you can use
the evaluateToImagemethods, which return a byte array
containg a GIF Image; if you wantto make it very simple,
you just make your control a JPanel thatcontains a JLabel,
and when you want to set a M_-GraphicsExpression (from a
Plot,...) you just set the GIF Image as the JLabels
Icon;something like this (jlPlot being the
JLabel):StdLink.requestTransaction();^Mbyte [] bGifData =
kl.evaluateToImage(sExpression, width,height);if (bGifData
== null || bGifData.length <= 1){
System.out.println(bGifData empty);}Image iPlot =
Toolkit.getDefaultToolkit().createImage(bGifData);
iiPlot.setImage(iPlot);jlPlot.setIcon(iiPlot);
jlPlot.repaint();murphee
====
> I am writing a Java
application that displays Mathematica output using >
MathCanvas. I am having difficulty in that the internal
frames > (JInternalFrame)in my application are covered by
the MathCanvas when > the internal frames are moved into the
MathCanvas area. I tried > setting the frame's layer to 0,
but that didn't work. Can anyone help > me out?I suppose
the problem is, that MathCanvas is an AWT Component,
whichcauses problem with the other Swing JComponents;2
possible solutions: - get J/Link 2.0, which comes with a
Swing version of MathCanvas(MathGraphicsJPanel if memory
serves); - if you can't do that, write a Swing replacement
for MathCanvasusing Swing; this is pretty simple: you can
use the evaluateToImagemethods, which return a byte array
containg a GIF Image; if you wantto make it very simple,
you just make your control a JPanel thatcontains a JLabel,
and when you want to set a M_-GraphicsExpression (from a
Plot,...) you just set the GIF Image as the JLabels
Icon;something like this (jlPlot being the
JLabel):StdLink.requestTransaction();^Mbyte [] bGifData =
kl.evaluateToImage(sExpression, width,height);if (bGifData
== null || bGifData.length <= 1){
System.out.println(bGifData empty);}Image iPlot =
Toolkit.getDefaultToolkit().createImage(bGifData);
iiPlot.setImage(iPlot);jlPlot.setIcon(iiPlot);
jlPlot.repaint();murphee
====
I am writing a Java
application that displays Mathematica output
usingMathCanvas. I am having difficulty in that the internal
frames(JInternalFrame)in my application are covered by the
MathCanvas whenthe internal frames are moved into the
MathCanvas area. I triedsetting the frame's layer to 0, but
that didn't work. Can anyone helpme out?
====
I wonder if
someone knows a fast way to import data from a tab-separated
file when numbers use coma (instead of point) as a decimal
separator.I know how to do this using:
Import[MyFile.txt,Table,ConversionOptions
->{NumberPoint->,}]However I got to noticed that Import is
far much time and memory consiming than ReadList[].Anyone as
an idea?TIA
====
> I am having a strange problem with a
function giving a complex number as > a result. I did the
following:> - define a function:> denom[x_, p_, d_] := Sqrt[1
+ (x*Tan[p]/d)^2]> Integrate and simplify it with the
assumption that d is larger than 0:>
FullSimplify[Integrate[denom[x, p, d], {x, 0, d}], d > 0]>
The result of the above line is >
d/2*(1+i*Sqrt[2]*d*Cos[p]^2)*Sqrt[Sec[p]^2] where i is
Sqrt[-1]> I assing it to a function called peter in the
following way:> peter[p_, d_] :=
FullSimplify[Integrate[denom[x, p, d], {x, 0, d}], d>0]>
and check the value of the function at [0,1]> peter[0,1]>
and the result is 1.> How is it possible that the result
doesn't have an imaginary part???> I would expect the result
to be 0.5+Sqrt[2]/2*i> You are evaluating the integral each
time that you call peter. Whenyou call it with p=0 denom is
evaluated to 1 before the integration.Define peter with
Evaluate or else don't use a delayed
set.denom[x_,p_,d_]:=Sqrt[1+(x*Tan[p]/d)^2];peter[p_,d_]:=
Evaluate[FullSimplify[Integrate[denom[x,p,d],{x,0,d}],d>0]];
peter2[p_,d_]:=FullSimplify[Integrate[denom[x,p,d],{x,0,d}],d
>0];peter[0,1](1/2)*(1 +
I*Sqrt[2])peter2[0,1]1peter2[10^-6,1]//N0.5 +
0.707107*Ipeter2[-10^-6,1]//N0.5 + 0.707107*IBob
HanlonChantilly, VA USA
====
(1) To discourage alteration of
the program file, save it as a binary file.Look up
DumpSave in
Help.(2) To discourage alteration of symbols within a
Mathematica session, usethe Locked attributed.(3) To finally
answer your question, use the ReadProtected attribute
onsymbols you would like viewers not to see.Hope this
helps,Tom
====
> I am having a strange problem with a
function giving a complex number as> a result...You should
perhaps examine the integral of denom. Do you really expect
acomplex result? The integral involves multibranched
functions (a fact maskeda bit by the form Tan[p] in the
integrand; try replacing Tan[p] by p to seewhat is going
on). Is your result on the branch you want? I suspect not;
youare probably after a real result. The following
modification produces a realresult: Integrate[denom[x, p,
d], {x, 0, d}, PrincipalValue -> True,GenerateConditions ->
False]But you'll need to take the limit p->0.Hope this
helps,Tom Burton
====
The integral doesn't converge when b
is real, because of the secondorder singularity at Abs[b]
in that case. Arg[b^2]!=0 is used toexpress this because
the issue is whether that singularity is on thepositive
x-axis.Behavior at 0 and Infinity are fine if
Re[a]>0, but
otherwise those areproblems too, so Mathematica has the
right answer in those terms. Ican't vouch for the formula
it comes up with when the conditions aremet, but it's not
closed-form in the usual sense anyway; but it'sclosed-form
in terms of functions MATHEMATICA is comfortable with!Bobby
Treat-----Original Message----- (Pi -
2*SinIntegral[a*Sqrt[-(1/b^2)]])), Integrate[1/(E^(a/x)*(-b^2
+ x^2)), {x, 0, Infinity}]]If b is Real then Arg[b^2]==0 and
Mathematica doesn't solve it.
Let'sdefinea function that
allows us to test specific values of a and b.f[a_, b_][x_] =
Exp[-a/x]/(x^2 - b^2);Integrate[f[2, 3][x], {x, 0,
Infinity}]Integrate::idiv : Integral of 1/(E^(2/x)*(-9 +
x^2)) does notconverge on{0, Infinity}.But if we use an
imaginary value for b...Integrate[f[2, 3I][x], {x, 0,
Infinity}]%//N(1/6)*(2*CosIntegral[2/3]*Sin[2/3] +
Cos[2/3]*(Pi - 2*SinIntegral[2/3]))0.254022David
Parkdjmp@earthlink.nethttp://home.earthlink.net/~djmp/
MasterÇs Degree of Applied Physics - Unesp/Rio Claro -
State
of S.8boPaulo - BrazilLaboratory of Electrical
Measurementsphone : ( 0XX19 ) 526 -
2237*********************************************************
************
====
> I solved the epidemic SIR ODE System>
(