# Plotting in a loop in mathematica

• Mathematica
• mummerta
In summary: I now have solutions and graphs running with 6 parameters!Hi, I have a problem with mathematica...I have two lists ...one is for temperature and the other is for time...and they are related..that is...each element in time list corresponds to temperature on the other list...I have a huge formula where i need to use corresponding elements from both lists... any suggestions ?If your two list are in list format such as:Time = {1, 2, 3, 4} and Temp = {4, 5, 6, 7}with the correspondence between (Time, Temp)(1,4)(2,5)(3,6)(
mummerta
I am trying to solve a system of differential equations and plot solution curves. The differential equations have parameters. I would like to write a loop for these parameters and have the solution curves plot.

Here is my code for the solving / plotting. The parameters I want to change are are currently 7 and 4.

sol = NDSolve[{x'[t] == -7*x[t] y[t] + 4 y[t],
y'[t] == 7*x[t] y[t] - 4 y[t], x[0] == 50, y[0] == 10}, {x,
y}, {t, 0, 10}]
Plot[Evaluate[x[t] /. sol], {t, 0, 1}, PlotRange -> All]
Plot[Evaluate[y[t] /. sol], {t, 0, 1}, PlotRange -> All]
ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 10},
PlotRange -> All]
{x[10], y[10]} /. sol

I don't know how to create a loop (or even which type of loop to use) that will output a plot for each new parameter value.

Any advice that you have to offer would be much appreciated.

Last edited:
Use the Table[..] function to do the loop.

First use Table[NDSolve[...],{i,Length[arr]}] to get an array of solutions for the parameters you want, where 'arr' is an array storing your parameters.

Then just do a similar loop for your plot. ie. Table[Plot[...],{i,Length[solArr]}], where solArr is the array of solutions that would have been returned from the previous line.

Thanks so much! I never would have thought to use a Table.

I now have solutions and graphs running with 4 parameters!

Hi, I have a problem with mathematica...I have two lists ...one is for temperature and the other is for time...and they are related..that is...each element in time list corresponds to temperature on the other list...I have a huge formula where i need to use corresponding elements from both lists... any suggestions ?

If your two list are in list format such as:

Time = {1, 2, 3, 4} and Temp = {4, 5, 6, 7}

with the correspondence between
(Time, Temp)
(1,4)
(2,5)
(3,6)
(4,7)

That is Time[] corresponds to Temp[]

Then you can use a Do loop in the following way:

Do[ put commands here separated by semicolons referencing i , {i,1,4} ]

For example

Do[Print[Time[]*Temp[];
Print[Time[]+Temp[], {i,1,4}]

You can join the sets dynamically. You can create a union. And most functions will iterate the lists, either as a union or indivdually.

## What is Plotting in a loop in Mathematica?

Plotting in a loop in Mathematica is a technique used to create multiple plots with varying parameters or data points in a single iteration. This allows for efficient and systematic exploration of data or functions.

## Why would I want to use Plotting in a loop in Mathematica?

Plotting in a loop in Mathematica is useful for visualizing the behavior of a function or data set with different inputs or conditions. It can also be used to compare and contrast multiple plots, making it a useful tool for analysis and problem-solving.

## How do I plot in a loop in Mathematica?

To plot in a loop in Mathematica, you can use the "Table" function to create a list of plots with varying parameters. Then, you can use the "Show" function to display all the plots together. Alternatively, you can use the "Manipulate" function to create an interactive loop where you can adjust the parameters and see the corresponding plot.

## Can I customize the plots in a loop in Mathematica?

Yes, you can customize the plots in a loop in Mathematica by using different plot options such as color, style, and labels. You can also add additional graphics or annotations to the plots using functions like "Graphics" and "Text".

## Are there any limitations to plotting in a loop in Mathematica?

While plotting in a loop in Mathematica is a powerful tool, it may not be suitable for very large or complex datasets. Additionally, the more plots you create in a loop, the longer it may take to generate and display them. It is also important to properly format and label your plots to avoid confusion or misinterpretation of the data.

• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
542
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
494
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
320
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
319
• MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
453
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K