Using matlab to find critical points?

For Problem 1 in the attached document, I am struggling to get the right answers. I cant seem to get the correct code to find the critical points and angles.
This is what I have so far:
pos_trap = zeros(size(vel_meas));
pos_trap(1) = 0.35; % Initial position of the piston
for k = 2:length(vel_meas)
pos_trap(k) = pos_trap(k-1) + 0.5*(vel_meas(k-1)+vel_meas(k))*DeltaT;
end
% Check accuracy of Trapezoid estimate
pos_actual = r*cos(w*t)+sqrt(L^2-r^2*sin(w*t).^2);
Error_trap = abs(pos_actual - pos_trap);

댓글 수: 4

Geoff Hayes
Geoff Hayes 2016년 3월 8일
Nick - how is the above code related to problem one in the document? How is the trapezoid estimate related to the problem since it is not mentioned at all?
That was the way we were taught in class, but I think I figured it out now. Does this look right?
r=0.03
L=0.5
w = 15.708
vel_meas = sym('-0.03*15.708*sin(Th) - 0.03^2*15.708*sin(2*Th)/(2*0.5)')
der1=diff(vel_meas,'Th')
CriticalPoints = solve(der1==0,'Th')
der2 = diff(der1,'Th');
der2_test = subs(der2,'Th',CriticalPoints)
CriticalPoints = double(CriticalPoints)*180/pi
Geoff Hayes
Geoff Hayes 2016년 3월 9일
Nick - I don't have the Symbolic Toolbox so can't comment on whether the above will give the correct answer or not. But it looks like you are using diff correctly to get the first and then second derivative of your function. Do you get similar results if you were to work through the problem by hand?
Better would be
syms Th
vel_meas = -0.03*15.708*sin(Th) - 0.03^2*15.708*sin(2*Th)/(2*0.5);
der1 = diff(vel_meas, Th)
CriticalPoints = solve(der1==0, Th)
Note: if you are using a MATLAB version before about R2011b, then change the "derl==0" to just "der1"

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2016년 3월 8일

댓글:

2016년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by