Finding the Maximum/Minimum value of a function

10 views (last 30 days)
This seems to be quite a simple thing to do, but for some ungodly reason i am having unimaginable trouble doing so, on my Casio calculator its simple as Pie, you put in the function and say find maximum between this point and this point, however I cant for the life of me figure out how to do it on this, and i tried a whole bunch of things that kept giving me errors, i was hoping if someone could help me with this it will be amazing.
What i would like to know is.... How to find the maximum of a function, I am not posting the whole code, just the thing that i am having trouble with..... and this is it....
x(t)=0.03106*exp(-21.43*t)*sin(32.2*t)
v(t)=diff(x(t));
a(t)=diff(v(t));
jerk(t)=diff(a(t));
G=solve(jerk(t)==0,t>0)
G=vpa(G,8)
ezplot (a(t),[0,0.5]) ; title a(t)
Now this is where the problem begins... to solve for maximum acceleration I am differentiating acceleration and then making that equal to ZERO, which should give me the time at which acceleration is ZERO However It is outputting a value for G which is not coherent with the ezplot, why? and how do I fix this?
Any help would be very greatfully appreciated and thanks in advance!!!
Just a little bit more info, It seems that whatever is "outisde" the ezplot the equation COMPLETELY diregards, it is wierd but i am telling the truth, at one point i wanted to find the maximum of x(t), which say it was at t=0.5 but it showed me the maximum to be t=0.46 JUST because the top of the graph was cut and 0.46 was the "maximum" of the graph that ezplot saw what is going on???? if someone can please confirm I am not insane that would be great.
  2 Comments
Walter Roberson
Walter Roberson on 23 Aug 2015
Is it correct that before this you have defined
syms x(t) v(t) a(t) jerk(t)
Eli Kroitor
Eli Kroitor on 25 Aug 2015
i havent before but i have now and it didnt make a difference

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 23 Aug 2015
What value of G is it outputting?
When you apply solve() to something that is not a polynomial, it is not certain that it will be able to find all of the roots; it might return only one numeric root and that one root could be anywhere. There are an infinite number of solutions spaced pi/32.2 apart. The first positive one is at approximately -(5/161)*arctan(10976809340/56816825393)+5/161*pi -- approximately because it depends on whether 0.03106 means 3106/10000 exactly or if the 0.03106 is to be interpreted as 0.03106 +/- 0.000005 .
  3 Comments
Walter Roberson
Walter Roberson on 25 Aug 2015
As you are going to name a numeric range:
G = vpasolve(jerk(t)=0, t, [0, 0.15])
0.15>t>0 does not mean what you would expect: it is parsed as ((0.15>t)>0) and the first part (0.15>t) returns a value of 1 if the condition is true and 0 if the condition is false. So you would then proceed to test either 1>0 or 0>0 . The first of those is of course true and the second is false -- which turns out to be the same as if you had just tested 0.15>t . In MATLAB break up your range tests
0.15 > 0 & t > 0
Eli Kroitor
Eli Kroitor on 25 Aug 2015
Hey walter thank you so much for that! I now understand what i did wrong, i never even knew vpasolve even exsisted! again thank you so much, i always seem to have trouble with the simplest things in matlab, I think something should be straight forward and easy awhich leads me to cutting corners, and when it doesent work i just get more and more impatient which just leads to more and more mistakes, Thanks again haha

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!