Message Boards Message Boards

0
|
7256 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to format mathematica projects for the end user. ??

Posted 9 years ago

So im messing around with mathematica and coded a few dynamic graphs of circular motion equations mostly to learn about and practice with mathematica dynamic graphing functions. At the end of the post is the full code of the program.

It outputs 4 sliders and 4 graphs. One after the other. like this :

Out[xxxx]= SLIDER 1

Out[xxxx]= SLIDER 2

Out[xxxx]= GRAPH 1

Out[xxxx]= GRAPH 2

Which is nice for debuging purposes but not so nice to look at since you can't even see all graphs at the same time, which is the whole purpose of the synchronised animations.

Now i have tried all of the notebook formatting options i could think about. even went into a few of the different screen environments (presentation,condensed,slideshow, etc) but they all pretty much look similar in that they all show the same information ( source code + unformatted graphs, sliders) in different styles.

My question is as follows, I would like to create a formatting for an end user such that the user can see and control the sliders but can't see or alter the working source code. most importantly, i would like to format the outputting of the graphs so that they lay on the screen in some way in which all can be seen at the same time. Possibly something like this;

SLIDER SLIDER
SLIDER SLIDER

GRAPH 1 GRAPH 2

GRAPH 3 GRAPH 4.

Basically i want a format that's nice to look at and interact with instead of the rough working format i currently have.

Could someone give me some pointers to good information about how to format mathematica documents to present to an end user ??
is what im asking for even possible ? Im looking for something akin to the nice formatting you get from the wolfram demonstration projects.

I have tried to find info online but am apparently not looking for the right words.

Any help would be appreciated. wether concrete examples or links to a good information source on the topic.
Any other comments on the code itself / possible errors / things to improve are not necessary but obviously welcomed. after all, this is just a project made to learn the mathematica language a little better.

Thanks in advance.
Manuel.T

PS. the code is dynamic but should be safe to run ( only basic mathematica internal variables are modified). Feel free to take a look and play with it. it's pretty fun.

omega = 1;
radius = 1;
theta = 0;
damping = 0;
t = 0;

 omegaD := Sqrt[1 - (damping^2)]* omega;

y[t_] := (r*(E^(-damping*omega*t)))*Sin[theta + (omegaD*t)];
x[t_] := (r*(E^(-damping*omega*t))) * Cos[theta + (omegaD*t)];
vy[t_] := y'[t];
ay[t_] := y''[t];
vx[t_] := x'[t];
ax[t_] := x''[t];
pos[t_] := {x[t], y[t]};
 vel[t_] := {vx[t], vy[t]};
 acc[t_] := {ax[t], ay[t]};

"angular velocity(rad/s)" Slider[Dynamic[omega], {0.1, 2}, 
  Appearance -> "Labeled"]
"Phase offset(rad)" Slider[Dynamic[theta], {0, 2*Pi}, 
  Appearance -> "Labeled"]
"radius(meters)" Slider[Dynamic[r], {1, 100}, 
  Appearance -> "Labeled"]
"damping factor" Slider[Dynamic[damping], {0, 1}, 
  Appearance -> "Labeled"]

position := 
  Plot[{ (x[t]), (y[t])}, {t, 0, 2*Pi}, 
   PlotLabel -> HoldForm["position(m)"] ];
velo := Plot[{ vx[t], vy[t]}, {t, 0, 2*Pi}, 
   PlotLabel -> HoldForm["velocity(m/s)"]];
accel := Plot[{ ax[t], ay[t]}, {t, 0, 2*Pi}, 
   PlotLabel -> HoldForm["acceleration(m/s^2)"]];
circle := ParametricPlot[{x[t], y[t]}, {t, 0, ((4*Pi)/omega)}, 
   PlotLabel -> HoldForm["motion"]];

Animate[Show[circle, 
  Graphics[{PointSize[Large], Red, {Point[Dynamic[{x[t], y[t]}]]}, 
    Blue, Arrow[{pos[t], pos[t] + (vel[t]*0.2)}], Green, 
    Arrow[{pos[t], pos[t] + (0.2*acc[t])}]}]], {t, 0, 2*Pi, 
  AppearanceElements -> None, LocalizeVariables -> False}]  

Animate[Dynamic[
  Show[position, 
   Graphics[{PointSize[Large], 
     Red, {Point[Dynamic[{t, y[t]}]], 
      Point[Dynamic[{t, x[t]}]]}}]]], {t, 0, 2*Pi, 
  AppearanceElements -> None, LocalizeVariables -> False}]  

Animate[
 Dynamic[Show[velo, 
   Graphics[{PointSize[Large], 
     Red, {Point[Dynamic[{t, vx[t]}]], 
      Point[Dynamic[{t, vy[t]}]]}}]]], {t, 0, 2*Pi, 
  AppearanceElements -> None, LocalizeVariables -> False}]  

Animate[Dynamic[
  Show[accel, 
   Graphics[{PointSize[Large], 
     Red, {Point[Dynamic[{t, ax[t]}]], 
      Point[Dynamic[{t, ay[t]}]]}}]]], {t, 0, 2*Pi, 
  AppearanceElements -> None, LocalizeVariables -> False}]  
POSTED BY: Manuel Telleria
2 Replies

I would try Manipulate.html where you can combine them all into one app. You can also export it to CDF file.

POSTED BY: Nasser M. Abbasi

Thanks for the reply. I will check out the manipulate function as it does seem like a better way to manipulate the variables. I have tried CDF before and did not manage to make it look any different to my notebook document. However, thanks for pointing out that's what i needed.

After a bit of searching i found this site: http://www.wolfram.com/training/courses/cdf/

Seems to have a lot of info. i will be checking it out for sure.

EDIT:

I've updated my code to the following. I managed to plot all graphs in one cell by putting them all inside the same animate function, since it's anyway only one parameter that is being animated.I managed to group the sliders with a the Row[] function. I also removed a lot of unnecessary dynamic tags which where now causing performance issues whit all graphs in the screen at once and also just generally slimed the code down.

I also found out you can also hide the source code AND make it uneditable by just clicking the desired cell and using the cell tab to change options for that cell.

omega = 1;
radius = 1;
theta = 0;
damping = 0;
t = 0;
omegaD := Sqrt[1 - (damping^2)]* omega;

Row[
 {"angular velocity(rad/s)" Slider[Dynamic[omega], {0.1, 2}, 
    Appearance -> "Labeled"]
  ,
  "Phase offset(rad)" Slider[Dynamic[theta], {0, 2*Pi}, 
    Appearance -> "Labeled"]
  ,
  "radius(meters)" Slider[Dynamic[r], {1, 100}, 
    Appearance -> "Labeled"]
  ,
  "damping factor" Slider[Dynamic[damping], {0, 1}, 
    Appearance -> "Labeled"]}]

y[t_] := (r*(E^(-damping*omega*t)))*Sin[theta + (omegaD*t)];
x[t_] := (r*(E^(-damping*omega*t))) * Cos[theta + (omegaD*t)];
vy[t_] := y'[t];
ay[t_] := y''[t];
vx[t_] := x'[t];
ax[t_] := x''[t];
pos[t_] := {x[t], y[t]};
 vel[t_] := {vx[t], vy[t]};
 acc[t_] := {ax[t], ay[t]};

position := 
  Plot[{ (x[t]), (y[t])}, {t, 0, 2*Pi}, 
   PlotLabel -> HoldForm["position(m)"] ];
velo := Plot[{ vx[t], vy[t]}, {t, 0, 2*Pi}, 
   PlotLabel -> HoldForm["velocity(m/s)"]];
accel := Plot[{ ax[t], ay[t]}, {t, 0, 2*Pi}, 
   PlotLabel -> HoldForm["acceleration(m/s^2)"]];
circle := ParametricPlot[{x[t], y[t]}, {t, 0, ((4*Pi)/omega)}, 
   PlotLabel -> HoldForm["motion"]];

Animate[{Show[circle, 
   Graphics[{PointSize[Large], Red, {Point[{x[t], y[t]}]}, Blue, 
     Arrow[{pos[t], pos[t] + (vel[t]*0.2)}], Green, 
     Arrow[{pos[t], pos[t] + (0.2*acc[t])}]}]], 
  Show[position, 
   Graphics[{PointSize[Large], 
     Red, {Point[{t, y[t]}], Point[{t, x[t]}]}}]], 
  Show[velo, 
   Graphics[{PointSize[Large], 
     Red, {Point[{t, vx[t]}], Point[{t, vy[t]}]}}]], 
  Show[accel, 
   Graphics[{PointSize[Large], 
     Red, {Point[{t, ax[t]}], Point[{t, ay[t]}]}}]]}, {t, 0, 2*Pi, 
  AppearanceElements -> False, LocalizeVariables -> False, 
  PerformanceGoal -> "Speed", ImageSize -> Large}]  
POSTED BY: Manuel Telleria
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