Message Boards Message Boards

GROUPS:

[✓] Shorthand to represent multiple expressions in a Plot[] function?

Posted 1 month ago
233 Views
|
3 Replies
|
1 Total Likes
|

There are 6 different calculated regressions on a data set. They are stored in a list labeled 'lfX'. Currently, these regressions are plotted with:

Plot[{lfX[[1]][x], lfX[[2]][x], lfX[[3]][x], lfX[[4]][x], lfX[[5]][x], lfX[[6]][x]}, {x, 0, 30}]

Is there an expression that would compact the multiple lfX[[i]] terms into something like lfX[[1..6]] or lfX[[All]]? All the plots must appear together in one chart, so a Do[] loop performing one Plot[] at a time wouldn't work.

A 6 element list of regressions is trivial, but the compaction would be very useful if the small 1 dimension list were expanded into a bigger, multi-dimension matrix. Could the compaction handle a SPARSE matrix of regression expressions?

3 Replies

Of course function heads can be arguments as well! For the one dimensional case try e.g.:

Plot[Evaluate[#[x] & /@ lfX], {x, 0, 30}]
Posted 1 month ago

Fantastic, Magnificent, wie, total wunderbar

I had no idea how to use Evaluate[] and Map[] for functions rather than parameters. This is definitely an educational episode. Now I believe I see how to process a density-1 2D matrix with a lvlspec (3rd param) on Map. A sparse matrix will be messier, but "Wait, Wait, Don't tell me"...

THANK YOU!

Glad you liked my answer! Just for completeness: Evaluate is only needed because Plot has the attribute HoldAll. And the more 'official' way would read:

Plot[Evaluate@Through[lfX[x]], {x, 0, 30}]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract