# How to graph separate functions from a loop and find their max's?

1 view (last 30 days)
Danielle Guariglia on 20 Apr 2021
Answered: Aghamarsh Varanasi on 23 Apr 2021
so i have a function that i need to change one variable a few different times.
I used a for loop and got a few different function outputs, which is what i want.
But i need to plot each one of those functions and find the absolute max on each one as well. I know it will be loops within loops i am just not sure how to call up each individual funtion to graph and then evaluate.
syms t
ymax = 0;
dt = .5;
for w = 4:dt:7
x = (4/(-w^2+36))*cos(6*t) + (2/3)*sin(6*t) - (4/(-w^2+36))*cos(w*t)
end
these are the functions i get in the command window
x =
cos(6*t)/5 - cos(4*t)/5 + (2*sin(6*t))/3
x =
(16*cos(6*t))/63 - (16*cos((9*t)/2))/63 + (2*sin(6*t))/3
x =
(4*cos(6*t))/11 - (4*cos(5*t))/11 + (2*sin(6*t))/3
x =
(16*cos(6*t))/23 - (16*cos((11*t)/2))/23 + (2*sin(6*t))/3
x =
NaN
x =
(16*cos((13*t)/2))/25 - (16*cos(6*t))/25 + (2*sin(6*t))/3
x =
(4*cos(7*t))/13 - (4*cos(6*t))/13 + (2*sin(6*t))/3
>>

Aghamarsh Varanasi on 23 Apr 2021
Hi,
You can use the 'fplot' function to plot a function or expression. To calculate the local maxima or local minima of a function, you can refer to this documentation page.
Hope this helps
The text passage is a MATLAB forum post where a user is asking for help on how to graph and find the maximum values of multiple functions generated from a loop. An answer is provided suggesting the use of the 'fplot' function and a link to documentation for finding local maxima or minima.
single_question_with_answer
Given a text passage, determine:
    1. If it contains a mathematical question (including word problems or calculations)
    2. If an answer to that mathematical question is provided in the text

First, describe the content structure you found in 1-2 sentences.

Then provide your analysis in the following format:
TYPE: <one of the following values>
- NO_QUESTION
- SINGLE_QUESTION
- SINGLE_QUESTION_WITH_ANSWER
- MULTIPLE_QUESTIONS
- MULTIPLE_QUESTIONS_WITH_ANSWERS
system
# How to graph separate functions from a loop and find their max's?

1 view (last 30 days)
Danielle Guariglia on 20 Apr 2021
Answered: Aghamarsh Varanasi on 23 Apr 2021
so i have a function that i need to change one variable a few different times.
I used a for loop and got a few different function outputs, which is what i want.
But i need to plot each one of those functions and find the absolute max on each one as well. I know it will be loops within loops i am just not sure how to call up each individual funtion to graph and then evaluate.
syms t
ymax = 0;
dt = .5;
for w = 4:dt:7
x = (4/(-w^2+36))*cos(6*t) + (2/3)*sin(6*t) - (4/(-w^2+36))*cos(w*t)
end
these are the functions i get in the command window
x =
cos(6*t)/5 - cos(4*t)/5 + (2*sin(6*t))/3
x =
(16*cos(6*t))/63 - (16*cos((9*t)/2))/63 + (2*sin(6*t))/3
x =
(4*cos(6*t))/11 - (4*cos(5*t))/11 + (2*sin(6*t))/3
x =
(16*cos(6*t))/23 - (16*cos((11*t)/2))/23 + (2*sin(6*t))/3
x =
NaN
x =
(16*cos((13*t)/2))/25 - (16*cos(6*t))/25 + (2*sin(6*t))/3
x =
(4*cos(7*t))/13 - (4*cos(6*t))/13 + (2*sin(6*t))/3
>>

Aghamarsh Varanasi on 23 Apr 2021
Hi,
You can use the 'fplot' function to plot a function or expression. To calculate the local maxima or local minima of a function, you can refer to this documentation page.
Hope this helps
user
The text passage is a MATLAB forum post where a user is asking for help on how to graph and find the maximum values of multiple functions generated from a loop. An answer is provided suggesting the use of the 'fplot' function and a link to documentation for finding local maxima or minima.

TYPE: SINGLE_QUESTION_WITH_ANSWER