Graphing Problem in Mathematica

In summary, the conversation discusses how to graph a program using Mathematica. The program involves calculating temperature values at different distances and times. The suggested method for graphing is to use the "Plot" and "ListPlot" functions in Mathematica, and the "Animate" function can also be used to create an animation.
  • #1
wolfie56
3
0

Homework Statement


I would like to graph the following program.


Homework Equations


L = 1.0; \[Kappa] = 1.; Num = 80; \[CapitalDelta]z = L/Num;
td = (\[CapitalDelta]z*\[CapitalDelta]z)/(2*\[Kappa]); \
\[CapitalDelta]t = 1.01*td; r = (\[CapitalDelta]t/(2*td));

Temp[0] = 10.; Temp[Num] = 10.;
Do[Temp = 10., {s, 1, (Num/2 - 6)}]; Do[
Temp = 50., {s, (Num/2 - 5), (Num/2 + 5)}]; Do[
Temp = 10., {s, (Num/2 + 6), (Num - 1)}]
data = Table[{ss*\[CapitalDelta]z, Temp[ss]}, {ss, 0, Num}];
ListPlot[data, PlotRange -> {-5, 55}, PlotStyle -> PointSize[0.02],
AxesLabel -> {"z", "T[z]"}, PlotLabel -> Initial Temp];

cycle = 0;
Do[Do[NewTemp =
Temp + r*(Temp[s - 1] - 2*Temp + Temp[s + 1]),
{s, 1, (Num - 1)}];
Do[Temp[ss] = NewTemp[ss], {ss, 1, Num - 1}]; cycle = cycle + 1;
If[cycle >= 1, t = n*\[CapitalDelta]t;
Print["time=", t, " iterations=", n];
data = Table[{sss*\[CapitalDelta]z, Temp[sss]}, {sss, 0, Num}];
ListPlot[data, PlotRange -> {-5, 55}, AxesLabel -> {"z", "T[z]"},
PlotStyle -> PointSize[0.02]]; cycle = 0],
{n, 1, 200}] cycle = 0;

The Attempt at a Solution


Mathematica gives me the time iterations, but no graphs. I don't know what to do; I want the graphs to show up.
 
Physics news on Phys.org
  • #2


Hi there,

Thank you for your post. To graph the program, you can use the "Plot" function in Mathematica. The syntax for "Plot" is as follows:

Plot[f[x], {x, xmin, xmax}]

where f[x] is the function you want to plot, and xmin and xmax are the minimum and maximum values for the x-axis. In your case, you can use the following code to plot the temperature data:

Plot[Temp[ss], {ss, 0, Num}, PlotRange -> {-5, 55}, AxesLabel -> {"z", "T[z]"}, PlotStyle -> PointSize[0.02], PlotLabel -> "Temperature vs. Distance"]

This will give you a plot of temperature vs. distance at a specific time. To plot the temperature over time, you can use the following code:

ListPlot[data, PlotRange -> {-5, 55}, AxesLabel -> {"z", "T[z]"}, PlotStyle -> PointSize[0.02], PlotLabel -> "Temperature vs. Time"]

This will give you a plot of temperature vs. time at different distances. You can also use the "Animate" function in Mathematica to create an animation of the temperature changing over time.

I hope this helps. Let me know if you have any further questions. Good luck with your graphing!
 

Related to Graphing Problem in Mathematica

1. How do I create a graph in Mathematica?

To create a graph in Mathematica, use the Plot function. This function takes in the equation or data points to be graphed, along with any desired options such as axis labels or plot style. For example, Plot[x^2, {x, -5, 5}, PlotStyle -> Red] will create a graph of the function y = x^2 from -5 to 5 with a red line.

2. Can I add multiple graphs to the same plot in Mathematica?

Yes, you can add multiple graphs to the same plot by using the Show function. This function allows you to combine multiple plots or graphics objects into one. For example, Show[Plot[x^2, {x, -5, 5}], Plot[x^3, {x, -5, 5}, PlotStyle -> Red]] will show both y = x^2 and y = x^3 on the same plot with the latter graph in red.

3. How do I change the appearance of a graph in Mathematica?

There are many options for customizing the appearance of a graph in Mathematica. Some common options include changing the plot style, adding labels or legends, and adjusting the axis scales. These options can be specified within the Plot function or using the PlotStyle, PlotLabel, and PlotRange options, respectively.

4. Can I export a graph from Mathematica to use in other programs?

Yes, you can export a graph from Mathematica in various formats such as JPEG, PNG, or PDF. To do so, use the Export function and specify the desired format and file name. For example, Export["mygraph.jpg", Plot[Sin[x], {x, 0, 2 Pi}]] will export the graph of y = sin(x) to a JPEG file named "mygraph" in the current directory.

5. How do I add error bars to a graph in Mathematica?

To add error bars to a graph in Mathematica, use the ErrorListPlot function. This function takes in data points along with their corresponding error values and plots them with error bars. For example, ErrorListPlot[{{1, 2, 0.2}, {2, 3, 0.3}, {3, 4, 0.4}}] will plot data points at (1,2), (2,3), and (3,4) with error bars of 0.2, 0.3, and 0.4, respectively.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
372
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
347
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top