## Finding corresponding x value for second graph

### Oskar (view profile)

on 19 Dec 2017
Latest activity Answered by Kelly Kearney

### Kelly Kearney (view profile)

on 19 Dec 2017
I made 2 graphs and need help finding the corresponding 'x' value for the second graph.
time_period = [0 181324/20000];
initial = [0, 0];
[t,y]=ode45(@myode45function, time_period, initial); %calls the ode45 function to plot y against t
plot(t,y(:,1)),title('Graph of y against t') %plots a graph of y against t
xlabel('t')
ylabel('y')
ymax=max(y(:,1));
disp('The maximum value of y is ')
disp(ymax);
position = find(y==ymax); %finds the position where y is at its maximum
Tmin=t(position); %and finds the corresponding value of t at this position
disp('The corresponding value of t when y is maximum is:')
disp(Tmin) %displays the value of t
figure; %new graph
plot(t,y(:,2)),title('Graph of dy/dt against t') %plots a graph of dy/dt against t with title
xlabel('t')
ylabel('dy/dt')
ymax1=max(y(:,2));
disp('The maximum value of dy/dt is: ')
disp(ymax1);
This is the function
function myoutput = myode45function(t,y)
myoutput = [y(2); 10*cos(t) - 12*y(2)-35*y(1)];
end
I tried doing this at the end of the code:
position2 = find(y==ymax1);
Tmin2=t(position2);
disp('The corresponding value of t when dy/dx is maximum is:')
disp(Tmin2)
end but i get an error saying "Index exceeds matrix dimensions. Error in assignment_five (line 22) Tmin2=t(position2);"