MATLAB: Finding the Maximum/Minimum value of a function

findingMATLABmaximumminimumsolving

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.

Best Answer

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 .