function or code can detect the increment of force equations ?
1 view (last 30 days)
Show older comments
i have some equations like: 10*e^t or 20+sin(t), ...etc. it's force function of time. of course i can tell by looking to the plot that 'e^t for example' will keep increase as the the time increases, for sinusoidal shapes will be constant and so on..
my question is there any function or codes can do the same ? i just put the equation in matlab and he tells me in the result if force increased with time or not.
2 Comments
jgg
on 25 Jan 2016
Why not just do this:
fun = @(t)(10*e^t);
increase = fun(0) > fun(1e10);
decrease = fun(0) < fun(1e10);
same = fun(0) == fun(1e10);
Or something like that?
Chad Greene
on 25 Jan 2016
Picking two points arbitrarily is sensitive to high-frequencies, such as in the case of sin(t). The low-frequency trend of sin(t) is zero, but if you pick sin(0) and sin(1e10) it'll give a negative trend.
Accepted Answer
Chad Greene
on 25 Jan 2016
You could fit a least squares trend line over some predefined range to determine slope.
% define some array of times:
t = 1:500;
% define a function:
f = 10*sin(t);
% fit a straight line to the function:
P = polyfit(t,f,1);
% Get the slope of the trendline:
slope = P(1);
% Round the slope of the trendline to prevent a few eps from adjusting the sign:
slope = fix(slope*1000)/1000;
% Does the function increase (1), decrease (-1), or remain constant (0)?
sign(slope)
% plot:
plot(t,f,'b')
hold on
plot(t,slope*t+P(2),'k')
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!