MATLAB How can I plot maximum values using a for loop in MATLAB?

AI Thread Summary
The discussion revolves around using a for loop to replace a number in a mathematical function with a variable defined as a range of numbers, specifically for plotting purposes. The user initially presents a code snippet that defines variables and functions, aiming to plot the maximum of a function based on a new variable. However, the proposed new program does not function correctly. A suggestion is made to modify the code by using element-wise operations (noted with the dot operator) to ensure proper calculations. The issue of division by zero is also raised, indicating that one of the calculations will result in an undefined value. The user clarifies their goal is to graph the maximum value of 't' for each corresponding 'x'.
physicsCU
Messages
198
Reaction score
1
I wish to use a for loop i already made and replace a number with a variable defined as a range of numbers, then plot the max of another function that used the function with the new variable.

How would I do this?

example:

x = [0:.5:1]
r = 5*x
t = 3/r

new program:

x = same
n = [0:.25:.5]
r = n*x
t = 3/r

for each value of n, i want to plot the cooresponding t, and plot n vs t
 
Last edited:
Physics news on Phys.org
I do not understand what it is you want to do. However your new program does not work. Try
x = [0:.5:1]
n = [0:.25:.5]
r = n.*x
t = 3./r

One of your r's will of course be zero, so you have a small problem with one t. if you want to plot it
plot(t,n)
 
yes, i know about mtimes

it was simply an example. i guess i want to graph the max t at each x.
 

Similar threads

Replies
2
Views
3K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
2
Views
2K
Replies
3
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Back
Top