Message Boards Message Boards

GROUPS:

Multiple Outputs on an Interactive Graph

Posted 6 years ago
5716 Views
|
2 Replies
|
0 Total Likes
|

Is it possible to have multiple outputs on an interactive graph. I am creating a demonstration for a econometrics class. I want to plot a series of fixed data points. Then I want to have sliders for two parameters of a linear function that will plotted on top of the points. On the same graph I would like to display the sum of squared residuals where each residual is the distance between the line and a point on the graph. The students would then use the sliders to select parameters that seem to fit the line to the points in the best way that they can. That is, in such a way as to minimize the sum of squared residuals.

In short, my question is. Can I plot fixed point, an interactive line, and an interactive numeric output all on the same interactive graph? I have been looking around and can't find anything like it.

2 Replies

Yes this can be programmed. Mathematica is also good choice for a platform to program this on.

How do you learn how to do this? The answer fundamentally is that you have to learn enough about programming Mathematica.

Let's make some example data that is linear and has some normally distributed noise added to it:

exampleData = Table[{x, 2 x + RandomVariate@NormalDistribution[]}, {x, 2, 5, 0.1}]
background = ListPlot[exampleData]

Now, we can make a function that takes a slope and intercept and plots a line with those values. Let's give it some test values and see what it looks like when we combine it with Manipulate:

plotOfLine[slope_, intercept_] := Plot[slope x + intercept, {x, 0, 6}, PlotStyle -> Red];
Show[background, plotOfLine[2, 3]]

Great. We want to make a dialog where we can adjust those values. Manipulate is a great choice for this.

Manipulate[Show[background, plotOfLine[slope, intercept]], {slope, 0.1, 3}, {intercept, 0, 3}]

enter image description here

You can add more features to this. It will require some programming however

Posted 6 years ago

This is what I needed to know. I know a very little about programming in Mathematica. I didn't want to invest time in learning what I needed to if it was not possible. Now I know that it is possible. Thanks!

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