*To*: mathgroup@smc.vnet.net*Subject*: [mg10571] Re: Plotting vector-valued functions*From*: Paul Abbott <paul@physics.uwa.edu.au>*Date*: Tue, 20 Jan 1998 16:54:13 -0500*Organization*: University of Western Australia*References*: <69na52$860@smc.vnet.net>

Malcolm Boshier wrote: > I have a problem which is related to the recent thread about > plotting lists of functions. In the case when a vector-valued function > is expensive or impossible to Evaluate before plotting, Plot apparently > forces you to evaluate the function repeatedly at each value of the > independent parameter. This can be very inefficient. > As an example, suppose that f[z] returns the eigenvalues of a 5 x 5 > matrix which is a function of z. Ok, say, In[1]:= m[z_] = {{2, 1, 9, 5, 1}, {5, 5, 1, 3, 7}, {9, 4, 8, 7, 5}, {3, 8, 1 + z, 8, 7}, {7 - 2*z, 2, 3, 8, 8}}; In[2]:= f[z_] := Eigenvalues[m[z]] > In general this function cannot be evaluated without a value for z, Actually, it _can_ be evaluated as a function of z in terms of (algebraic) Root objects. Try entering f[z]. > so Plot[ Evaluate[f[z]], {z, zmin, zmax}] doesn't work. This does work for me: In[3]:= Plot[Evaluate[Re[f[z]]], {z, -10, 10}]; > The only way around this that I have found is something like: > > Plot[{f[z][[1]], f[z][[2]], f[z][[3]], f[z][[4]], f[z][[5]]}, {z, zmin, > zmax}] > > which of course requires 5 evaluations of f[z] for each value of z. Dynamic programming can be used to avoid this. E.g., you could define In[3]:= f[z_?NumericQ] := f[z] = Eigenvalues[m[z]] Then, when f[z][[1]] is evaluated for a particular z, f[z] is recorded and saved. Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul@physics.uwa.edu.au AUSTRALIA http://www.pd.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________