Subject: FindRoot and Compile
The following used to work in 4.2
y = Compile[{x}, x^2 - 2 == 0]
FindRoot[y[x], {x, .9}]
{x -> 1.41421}
With 5.01 I get the Message:
CompiledFunction::cfsa: Argument x at position 1 should be a
machine-size real number
In this case I did not get the trick with_?NumericQ to work . Maybe I
am not doing it correctly.
Any suggestions?
Matthias
--
PD Dr. Matthias Gottschalk
GeoForschungsZentrum
Projektbereich 4.1
Telegrafenberg
14473 Potsdam
Germany
tel/fax +49 (0) 331 288-1418/1402
===
Subject: Excessive Mathematica memory use, revisited.
Content-Class: urn:content-classes:message
September,
Windows XP, Mathematica 5.0.0.
My goal is still to manipulate very large images. Currently I am trying
to use Experimental`BinaryImport to import an ~ 500MB image into
Mathematica. Each sample is an unsigned 16-bit integer.
I start the Windows Task Manager, display the process list, and sort by
memory usage.
Then, after issuing the following commands to a cold kernel, I watch the
Mathematica kernel rise to the top of the above list, consume chunks of
memory in steps of maybe 20MB, and exhaust physical memory.
< How can I efficiently build a symmetric matrix from an upper triangular
> one, i.e., extract the upper triangular elements and insert them into
> the lower triangle in such a way as to make the resulting square matrix
> symmetric?
> Mark
My solution :
In[1]:=
symmetrize[m_]:=
With[{mi=MapIndexed[Table[0,{#2[[1]]}]~Join~Drop[#1,#2[[1]]]&,m]},
mi+Transpose[mi]+IdentityMatrix[Length[m]]*m
];
In[2]:=m={{1,2,3},{0,5,6},{0,0,9}};
In[3]:=symmetrize[m]
Out[3]={{1,2,3},{2,5,6},{3,6,9}}
hth
--
0% de pub! Que du bonheur et des vrais adh.8erents !
Vous aussi inscrivez-vous sans plus tarder!!
Message post.8e .88 partir de http://www.gyptis.org, BBS actif depuis
1995.
===
Subject: Re: Creating a symmetric matrix
> How can I efficiently build a symmetric matrix from an upper triangular
> one, i.e., extract the upper triangular elements and insert them into
> the lower triangle in such a way as to make the resulting square matrix
> symmetric?
> Mark
The most natural way must be
A+Tranpose[A]
e.g.
A = Array[KroneckerDelta[#1 < #2, True] & , {3, 3}];
{{0, 1, 1}, {0, 0, 1}, {0, 0, 0}}
A + Transpose[A]
{{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}
Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/
===
Subject: Re: Creating a symmetric matrix
Hi Mark,
I this this one should be pretty efficient
In[1]:=
Symmetrize[mat_] := mat + Transpose[mat] -
DiagonalMatrix[Flatten[MapIndexed[#1[[#2]] & , mat]]];
given upper(or lower) triangular matrix mat at the input,
it adds its transposed and subtracts the diagonal.
I ran some tests, the time it takes is quadratic in
the size of mat, yet the time is considerable smaller
that it took to create random upper-triangular matrix.
Here is the code used
In[2]:=
getUpperTriangular[dim_] := Table[If[n > m, 0,
Random[Integer, {1,100}] ], {n, 1, dim}, {m, 1, dim}];
In[3]:=
SetAttributes[getTiming, {HoldAll, SequenceHold}]
getTiming[expr_] := Timing[expr][[1]] /. {Second -> 1}
In[4]:=
symt = {}; creat = {};
Do[creat = Append[creat, {dim, getTiming[mat = getUpperTriangular[dim]]}];
symt = Append[symt, {dim, getTiming[res = Symmetrize[mat]]}]; ,
{dim, 10, 2000, 100}]
In[5]:=
ListPlot[symt] (* Graph of time it takes to symmetrize *)
In[6]:=
ListPlot[symt] (* Graph of time it takes to create the u-t. matrix *)
It takes 3.4 seconds to symmetrize a random matrix of 3000 x 3000
integers on my P4 2.0GHz w/ 768MB. And it took almost 18 seconds to
create such a matrix.
Best,
Sasha
How can I efficiently build a symmetric matrix from an upper triangular
> one, i.e., extract the upper triangular elements and insert them into
> the lower triangle in such a way as to make the resulting square matrix
> symmetric?
> Mark
>
--
Office: 6H Osmond Web: http://www.pavlyk.com
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No trees were destroyed to send this mail,
but a lot of electrons were terribly disturbed.
===
Subject: Re: Creating a symmetric matrix
ll = PadRight[#, 4, 0] & /@ Table[a[j, i], {j, 1, 4}, {i, 1, j}];
ll = ll + MapIndexed[If[Equal @@ #2, 0, #1] & , Transpose[ll], {2}]
??
Jens
> How can I efficiently build a symmetric matrix from an upper triangular
> one, i.e., extract the upper triangular elements and insert them into
> the lower triangle in such a way as to make the resulting square matrix
> symmetric?
> Mark
===
Subject: Re: Creating a symmetric matrix
> ll = PadRight[#, 4, 0] & /@ Table[a[j, i], {j, 1, 4}, {i, 1, j}];
> ll = ll + MapIndexed[If[Equal @@ #2, 0, #1] & , Transpose[ll], {2}]
How about
ll = PadRight[#, 4, 0] & /@ Table[a[j, i], {j, 1, 4}, {i, 1, j}];
ll + Transpose[ll] - DiagonalMatrix[Tr[ll, List]]
instead?
Paul
> Jens
How can I efficiently build a symmetric matrix from an upper triangular
> one, i.e., extract the upper triangular elements and insert them into
> the lower triangle in such a way as to make the resulting square matrix
> symmetric?
> Mark
--
Paul Abbott Phone: +61 8 9380 2734
School of Physics, M013 Fax: +61 8 9380 1014
The University of Western Australia (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009 mailto:paul@physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul
===
Subject: RE: Creating a symmetric matrix
Mark,
Here's one method.
maketest[n_] :=
Module[{mat = IdentityMatrix[n], i},
Do[Part[mat, i] = PadLeft[Table[a[i, j], {j, i, n}], n], {i, 1, n}];
mat]
(testmat = maketest[3]) // MatrixForm
triangularToSymmetric[mat_?MatrixQ] /; Equal @@ Dimensions[mat] :=
Module[{workmat = mat + Transpose[mat], i},
Do[Part[workmat, i, i] = Part[mat, i, i], {i, 1, Length[workmat]}];
workmat]
triangularToSymmetric[testmat] // MatrixForm
I added the matrix to its transpose and then replaced the diagonal elements
from the original matrix. I wish there were a way I could replace the
diagonal elements all at once.
I'm interested in seeing the other answers you will get.
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
How can I efficiently build a symmetric matrix from an upper triangular
one, i.e., extract the upper triangular elements and insert them into
the lower triangle in such a way as to make the resulting square matrix
symmetric?
Mark
===
Subject: RE: Font size
Jake,
You could make your own style sheet and then convert your notebooks to that
style sheet.
1) Start a fresh Mathematica session with a Default style notebook.
2) Use Menu/Format/Edit StyleSheet
3) Choose Edit Shared Style Sheet
4) Save the notebook that comes up under a new name. Say TrexelStyle.nb
(When I tried this I just left it in the standard StyleSheets folder where
the other style sheets are but it should probably be put in a private
FrontEnd/StyleSheets folder. You should probably contact WRI for the exact
location of this because I am not certain.)
5a) Open up the Styles for Input/Output section and the Input subsection.
Select the Input cell and then use Menu/Format/Size to adjust the font
size.
5b) Or you could select the cell, get the underlying expression by using
Shift-Ctrl-E and then set the font characteristics with options. Use
Shift-Ctrl-E to get back to StandardForm again.
6) Do the same thing for the Text cells and any other cells types you want
to change.
7) Save the notebook again
8) Whenever you open a new notebook use Menu/Format/StyleSheet and choose
TrexelStyle. Then the notebook will always be in that style.
I hope you can make the fonts large enough.
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
How can I change the font size, so that I can see it better ?
I want the font to larger when I do text and when I do any math.
How do I go about doing this ? I want it to stay that way all the
time. I have used the mag. to 300 % but with my eyes it is still to
small. I don't like to change it each and every time I type a new
section such as from text to equations and back and forth.
jake
===
Subject: Undiscovered Bug?
MathGroup:
In Mathematica 5.0.1 with Windows 2000, I mistakenly used the [[{}]]
operator on x/y. I was expecting an error, but I kept getting unusual
results as shown in In/Out's 2 to 5 below.
Have I stumbled on a bug, or is there a way to make sense out of this?
In[1]:= TreeForm[x/y]
Out[1]//TreeForm= Times[x, | ]
Power[y, -1]
In[2]:= (x/y)[[{2,2}]]
Out[2]= -2
y
In[3]:= (x/y)[[{1,2,1}]]
2
x
Out[3]= --
y
In[4]:= (x/y)[[{2, 2, 2, 2}]]
-4
Out[4]= y
In[5]:= (x/y)[[{2, 1, 1, 0, 2, 2, 0}]]
2 2
Times x
Out[5]= ---------
3
y
Harold
===
Subject: Re: Symbolic matrix manipulation
Does anyone have an answer to this that doesn't require access to a
journal for which I have no subscription?
david
>>I'd like to know how one can perform symbolic matrix-vector
>>manipulations in Mathematica, without having to specify the contents
>>of the matrices or vectors.
>>For example, imagine I have a vector-valued function
>>f(x) = x^T A
>>where A is a m x n matrix, x is an m-vector, and ^T indicates
>>transposition
>>How can I differentiate f(x)---or perform other symbolic operations
>>using matrices or vectors---such that I get the result in terms of A
>>and x (i.e. I don't want to have to specify that
>>A={{a11, a12, a13}, {a21, a22, a23}, {a31, a32, a33}} or whatever).
>>So, in the example above, I want Mathematica to tell me the answer is
>>d/dx (f) = A
>>I'd appreciate your advice on this matter.
> See The Mathematica Journal 8(4) (2002): 529-531
Paul
>
--
Replace spam with david if you wish to send email to my directly.
===
Subject: RE: Font size
If magnification ->300 doesn't help, you can still use Format | Size to
change the font size. However, too big a font size will make it difficult
to see a line of text within the screen. Choose Format | Option Inspector |
Formatting Options | FontOptions | FontSize to make this permanent for your
notebook or for all your notebooks (choose Global).
Tomas Garza
Mexico City
Original Message:
-----------------
===
Subject: Font size
How can I change the font size, so that I can see it better ?
I want the font to larger when I do text and when I do any math.
How do I go about doing this ? I want it to stay that way all the
time. I have used the mag. to 300 % but with my eyes it is still to
small. I don't like to change it each and every time I type a new
section such as from text to equations and back and forth.
jake
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
===
Subject: RE: Creating a symmetric matrix
In[1]:=
anyMat = {{a, b, c}, {d, e, f}, {g, h, i}};
In[2]:=
symMat = Table[If[m >= j, anyMat[[m,j]],
anyMat[[j,m]]], {m, 1, 3}, {j, 1, 3}]
Out[2]=
{{a,d,g},{d,e,h},{g,h,i}}
Tomas Garza
Mexico City
Original Message:
-----------------
===
Subject: Creating a symmetric matrix
How can I efficiently build a symmetric matrix from an upper triangular
one, i.e., extract the upper triangular elements and insert them into
the lower triangle in such a way as to make the resulting square matrix
symmetric?
Mark
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
===
Subject: Re: How to give back to an image using Net/Link and
asp.net?
Hello Michel
It already modifies the lines that you indicated to me, but still
profit not to show the image in WebForm1.aspx
Next I show the code to you of the archives: WebForm1.asp,
WebForm2.aspx and WebForm2.aspx.vb to see if you can please find some
error or something that I need.
----------------------------------------------------------------------------
WebForm1.aspx:
<%@ Page Language=vb AutoEventWireup=false
Codebehind=WebForm1.aspx.vb Inherits=WebCalculo.WebForm1%>
WebForm1
---------------------------------------------------------------------------
WebForm2.aspx:
<%@ Page Language=vb AutoEventWireup=false
Codebehind=WebForm2.aspx.vb Inherits=WebCalculo.WebForm2%>
----------------------------------------------------------------------------
WebForm2.aspx.vb:
Imports System.Drawing
Imports System.Drawing.Imaging
Imports Wolfram.NETLink
Public Class WebForm2
Inherits System.Web.UI.Page
Private mathKernel As New Wolfram.NETLink.MathKernel
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If (mathKernel.IsComputing()) Then
mathKernel.Abort()
Else
mathKernel.CaptureGraphics = True
mathKernel.Compute(Plot[x,{x,0,1}])
mathKernel.Graphics(0).Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
End If
End Sub
End Class
> Hi.
WebForm2.aspx
> HTML page should contain only the page directive
<%@ Page ... Should also have
EnableSessionState = False enableViewStae=False aspCompat=True
No html code at all.
in the code behind
I think your missing this
Do not use Response.Write and don't ne to tell the content type.
> just use
> mathkernel.Graphics(0).Save(Response.OutputStream,
> System.Drawing.Imaging.ImageFormat.Jpeg)
Hans
===
Subject: A tricky PDE system
I have the following PDE system to solve.
The variables are
vector R[z,t]={r_i[z,t]} subject to boundary condition R[z,t=0]=R0
scalar a[z,t] with boundary condition a[z=0,t]=f[t]
scalar b[z,t] with boundary condition b[z=L,t]=g[t]
(a and b are two laser pulses counter-propagating through a medium of
length L and the density of the medium - atomic populations - is
described by vector R, and i=1,..,4).
The equations to be solved subject to the above b.c. are:
d(r_i[z,t])/dt = Xi[ R[z,t], a[z,t], b[z,t] ]
d(a[z,t])/dz = F[ R[z,t], b[z,t] ]
d(b[z,t])/dz = G[ R[z,t], a[z,t] ]
where Xi, F, and G are linear functions.
I tried using NDSolve to solve the system but Mathematica doesn't
really recognize it as a PDE system. And I'm note sure that method of
lines is aplicable here since boundary conditions for fields a[z,t]
and b[z,t] are on the different sides of the medium. I know that
physically the problem is well-defined.
Is there perhaps any form of a differential-algebraic system that one
could do here to solve the system? Setup my own
difference-approximation acheme? Any other ideas?
-mik
===
Subject: Integrate vs NIntegrate
I am confused why NIntegrate misbehaves on such a simple function as mine.
Here is what I have:
In:
f=D[1/(1+(1+(a-b)^2)),a];
g=Integrate[f*b*(1-b)^2,{b,0,1},Assumptions->00.397207
However, since Integrate takes long, I tried to use NIntegrate instead and
this is what I get
In:
f=D[1/(1+(1+(a-b)^2)),a];
g:=NIntegrate[f*b*(1-b)^2,{b,0,1}];
FindRoot[g==0,{a,0,1}]
Out:
a->1
or, FindRoot+NIntegrate give me the upper boundary of a. If I abandon the
secant method and turn to Newton, i.e. use
FindRoot[g==0,{a,0.5}] instead then I get the message that Jacobian is
singular at a=0.5 and get no solution. Perturbing the starting value of a
does not help.
What is going on here?
PS. Is there a way to get M5 to tackle the problem where:
(1) I define some function f[x]:=NIntegrate[g[x,y],{y,0,1}], then
(2) take the derivative of f[x] with respect to x, say h[x]:=f'[x] and then
(3) Use FindRoot to find x such that h[x]==0
===
Subject: Re: Font size
>How can I change the font size, so that I can see it better ? I
>want the font to larger when I do text and when I do any math. How
>do I go about doing this ? I want it to stay that way all the
>time. I have used the mag. to 300 % but with my eyes it is still
>to small. I don't like to change it each and every time I type a
>new section such as from text to equations and back and forth.
Highlight/select the stuff you want larger and use the Format->Size->Larger
menu item. On a Mac with Mathematica 5.0, you can use the key combination
cmd= to increase font size and cmd- to decrease font size.
--
===
Subject: Mathematica to Word
This must have been asked 1000 times, but I haven't seen the
answer. I have a large but ordinary-looking file of Mathematica text output
on
the screen with no special characters, unusual formatting, lines, or
colors, Just plain text. I want to get this data, just as it looks,
into MS Word for further processing. When I convert the Mathematica output
to
text or do anything else I can think of, I get a very complex format
in Word, which would take a complicated macro to undo. There must be a
simple way to get real, plain text with no mysterious codes, etc., in
the Mathematica output file.
Steve Gray
===
Subject: RE: simple bug about Sum/Product function?
Yuko,
It may have worked in Version 4.2, but it is not a documented form of the
expression. The proper expression would be
Sum[1, {i,1000001}]
Sometimes undocumented features will work but you can't count on them in
future versions. I think that is what happened in this case.
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
Hello there,
Try the following simple expressions in Mathematica(ver5)
Sum[1, {1000001}]
Product[1, {1000001}]
There are no problems in ver 4.2.
Yuko MATSUDA
===
Subject: Re: Graphs of Sequences of Functions:(
Hi!
You can use the Table construct, either displaying the sequence of graphs
overlaid or each
of the them seperately:
together=Plot[Evaluate[Table[x^n, {n, 5}]], {x, 0, 1}]
sep=Table[Plot[x^n, {x, 0, 1}], {n, 5}]
Or you can display the last sequence as one image:
Show[ GraphicsArray[ Partition[sep, 1]]]
A question from me:
Why doesn't the command:
< Hi all,
> I am trying to do the graphs of some sequences of functions,using
> mathematica 4.0, in order to see if their convergence is uniform or not.
> For example : Fn(x) = x^n , 0=< x =<1.
> The problem is that the graphs have to be 2D (not 3D) but I cannot
> find a way to do that. Any suggestions?
> THANK YOU!
> Eleanna
===
Subject: Re: Graphs of Sequences of Functions:(
nmax = 4;
Plot[Evaluate[
Table[x^n, {n, 0, nmax}]],
{x, 0, 1},
PlotStyle -> Table[
Hue[(n + nmax)/(2nmax)],
{n, 0, nmax}]];
Bob Hanlon
<< I am trying to do the graphs of some sequences of functions,using
mathematica 4.0, in order to see if their convergence is uniform or not.
For example : Fn(x) = x^n , 0=< x =<1.
The problem is that the graphs have to be 2D (not 3D) but I cannot
find a way to do that. Any suggestions?
===
Subject: RE: Graphs of Sequences of Functions:(
Eleanna,
How about...
Needs[Graphics`Colors`]
Plot[Evaluate[Table[x^n, {n, 0, 10}]], {x, 0, 1},
PlotRange -> All,
Frame -> True,
FrameLabel -> {x, f},
RotateLabel -> False,
PlotLabel -> SequenceForm[f == x^n, as n goes from 0 to 10],
Background -> Linen,
ImageSize -> 450];
We make a table of the functions. The Table has to be evaluated in the Plot
statement for the Plot statement to work correctly. PlotRange -> All is
necessary else Mathematica just shows what it thinks is the interesting
part.
We obtain a better representation by using an uneven set of integers for n.
How do we do that with a Table? We can't but we can do it with MapThread.
For example...
MapThread[x^#&,{{0, 1, 2, 3, 5, 10, 20, 50, 100}}]
{1, x, x^2, x^3, x^5, x^10, x^20, x^50, x^100}
MapThread is a way to make a table with arbitrary values. x^#& is a pure
function. Then the following gives a more indicative plot.
Plot[Evaluate[MapThread[x^# &, {{0, 1, 2, 3, 5, 10, 20, 50, 100}}]], {x, 0,
1},
PlotRange -> All,
Frame -> True,
FrameLabel -> {x, f},
RotateLabel -> False,
PlotLabel -> SequenceForm[f == x^n, for increasing n from 0 to
100],
Background -> Linen,
ImageSize -> 450];
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
Hi all,
I am trying to do the graphs of some sequences of functions,using
mathematica 4.0, in order to see if their convergence is uniform or not.
For example : Fn(x) = x^n , 0=< x =<1.
The problem is that the graphs have to be 2D (not 3D) but I cannot
find a way to do that. Any suggestions?
THANK YOU!
Eleanna
===
Subject: Re: AES implementation in Mathematica
> I have updated my implementation of AES (Advanced Encryption Standard,
> also known as Rijndael) in Mathematica (requires v. 4.0 or higher). It
> now supports ECB, CBC and CFB128 modes, as well as several variants of
> AES-based CBC-MAC authentication, including OMAC. It is available at:
> http://library.wolfram.com/infocenter/MathSource/5130
> Jose Luis.
Jose,
I will certainly have a look at this.
Why did you not do Counter (CTR) mode. You can find this mode in the NIST
document.
I believe it will be one of the more popular modes due to some of its
properties.
===
Subject: shade area between vertical lines
Hello.
I know that it is possible to have Mathematica generate a plot that
shows the area shaded in between the lines y=1 and y=2 with something like:
< {-1, 5}]
This makes a lovely display of the open set in R^2 {(x,y):1 schrieb im Newsbeitrag
> The following used to work in 4.2
> y = Compile[{x}, x^2 - 2 == 0]
> FindRoot[y[x], {x, .9}]
> {x -> 1.41421}
> With 5.01 I get the Message:
> CompiledFunction::cfsa: Argument x at position 1 should be a
> machine-size real number
> In this case I did not get the trick with_?NumericQ to work . Maybe I
> am not doing it correctly.
> Any suggestions?
> Matthias
> --
> PD Dr. Matthias Gottschalk
> GeoForschungsZentrum
> Projektbereich 4.1
> Telegrafenberg
> 14473 Potsdam
> Germany
> tel/fax +49 (0) 331 288-1418/1402
Hi Matthias,
y[x_?NumericQ]:=Evaluate[Compile[{t},t^2-2]][x]
doesn't work? I do not have access to Version 5 - so i have to guess :-(
--
Peter Pein, Berlin
petsie@arcAND.de
replace && by || to write to me
===
Subject: Mathematica 5: Integration bug in quadratic found by the GEMM
machine
Here is, just of pure curiosity, a sample from my GEMM machine:
$Version
Integrate[1/(-2 z^2 + 3 z - 1), {z, -1, 0}]
Log[3/2] // invalid answer
0.405465
NIntegrate[1/(-2*z^2 + 3*z - 1), {z, -1, 0}]
-0.405465
But the above is just a good opportunity: actually, ' am writing
never published bug reports on a certain system is coming within
several next days after which we will operate at a new level
of speed; he who watches the activity knows well what I mean.
Best wishes,
Vladimir Bondarenko
http://www.cybertester.com/
http://www.CAS-testing.org/
===
Subject: solving for variable and then get these e's..?
Hello Group.
I was playing around with lorenz system again. I assigned random
numbers for all the parameters. and made a steady state system based
on that and solved for the variables. and I get the following. ( the
code is at the bottom)
{y[0] == 0.1889025652295933*(-1.3382047869208344 -
0.47590327034877034*Sqrt[7.906927918602607 -
18.515309886236974*e]),
x[0] == 0.31792235868739005*(1.5727110293983604 +
0.5593002876087739*Sqrt[7.906927918602607 -
18.515309886236974*e]),
z[0] == 0.042970475451898735*(7.906927918602607 +
2.8119260158479644*Sqrt[7.906927918602607 -
18.515309886236974*e]}
What are those little e's at the end of the solutions? Is that euler's
number? and why can't I use that in NDSolve routine? are those
signifcant?
any thoughts are appreciated.
In[270]:=
ode = {x'[t]== -a y[t]-b z[t],y'[t]== c x[t]+d y[t],
z'[t] == e-f z[t]+f x[t] z[t]}
%/._'[t]->0
Solve[%,{x[t], y[t], z[t]}]
%/.{a-> Random[Real, {1, 3}], b-> Random[Real, {1, 3}],
c-> Random[Real, {1, 3}],d-> Random[Real, {1, 3}],
d-> Random[Real, {1, 3}],f-> Random[Real, {1, 3}]}/.Rule ->Equal/.t->
0 //InputForm
s1 =% [[1]]
s2 = %%[[2]]
NDSolve[Join[{x'[t][Equal]-a y[t]-b z[t],y'[t][Equal]c x[t]+d y[t],
z'[t][Equal]e-f z[t]+f x[t] z[t]}, s1], {x[t], y[t], z[t]}, {t,
0, 10}]
===
Subject: Re: Re: Undiscovered Bug?
> MathGroup:
> When expr is a list, expr[[{i1, i2, ... in ]] gives a list of
> parts. In general, the head of expr is applied to the list of parts.
> ReplacePart's behavior, however, produces a different result ...
> Recall, we had for Part ...
> In[5]:= (x/y)[[{2, 1, 1, 0, 2, 2, 0}]]
> 2 2
> Times x
> Out[5]= ---------
> 3
> y
> But, we have for ReplacePart ...
> In[1]:= ReplacePart[(x/y), a, {2, 1, 1, 0, 2, 2, 0}]
> x
> ReplacePart::partw: Part {2, 1, 1, 0, 2, 2, 0} of - does not
> exist.
> y
> Maybe I'm still missing something, but it seems to me Part should be
> revised to detect the same errors as ReplacePart.
> Harold
What errors? There was no error in the syntax in your first (Part)
example so what should be detected? You made an error but the
Mathematica syntax was correct and after all Mathematica is not yet
able to read minds. As for ReplacePart: its syntax is different from
Part so you get a different result. ReplacePart and Part serve a
different purpose so why should their syntax be the same? Besides, in
any case, with ReplacePart you can eqaually well get results to inputs
that you might enter by mistake, e.g.:
In[3]:=
ReplacePart[(x/y), a, Partition[{2, 1, 1, 0, 2, 2, 0},1]]
Out[3]=
a(a,a)
Andrzej Kozlowksi
===
Subject: Re: Undiscovered Bug?
It's still not an error; just an interface you haven't learned.
It would be less confusing if Part and ReplacePart used the same
notation for parts, but they don't, so... We just have to adjust.
indices = {2, 1, 1, 0, 2, 2, 0};
(x/y)[[indices]]
(Times^2*x^2)/y^3
ReplacePart[x/y, a, List /@ indices]
a[a, a]
List /@ indices
{{2}, {1}, {1}, {0}, {2}, {2}, {0}}
This gives the error you want:
(x/y)[[Sequence @@ indices]]
Bobby
> MathGroup:
> When expr is a list, expr[[{i1, i2, ... in ]] gives a list of
> parts. In general, the head of expr is applied to the list of parts.
ReplacePart's behavior, however, produces a different result ...
Recall, we had for Part ...
In[5]:= (x/y)[[{2, 1, 1, 0, 2, 2, 0}]]
2 2
> Times x
> Out[5]= ---------
> 3
> y
But, we have for ReplacePart ...
In[1]:= ReplacePart[(x/y), a, {2, 1, 1, 0, 2, 2, 0}]
x
> ReplacePart::partw: Part {2, 1, 1, 0, 2, 2, 0} of - does not
> exist.
> y
Maybe I'm still missing something, but it seems to me Part should be
> revised to detect the same errors as ReplacePart.
Harold