Matlab 曲线到定点距离最短问题已知x(t)=5t-10,y(t)=25t^2-120t+144.t在[0,4]之间,求曲线到(0,0)的最短距离.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 11:02:23
Matlab 曲线到定点距离最短问题已知x(t)=5t-10,y(t)=25t^2-120t+144.t在[0,4]之间,求曲线到(0,0)的最短距离.
Matlab 曲线到定点距离最短问题
已知x(t)=5t-10,y(t)=25t^2-120t+144.
t在[0,4]之间,求曲线到(0,0)的最短距离.
Matlab 曲线到定点距离最短问题已知x(t)=5t-10,y(t)=25t^2-120t+144.t在[0,4]之间,求曲线到(0,0)的最短距离.
You can use Matlab's symbolic package to get the minimum distance, you might need to use a little bit calculus
t = sym('t','real') % define a real symbol variable
x=5*t-10;
y=25*t.^2-120*t+144;
d = (x^2+y^2)^.5; % distance function
d1 = diff(d); % the differentiation
t1s = solve(d1); % let the differentiation equal to 0 to get the maxmin point
t1v = eval(t1s); % get the numerical evaluation
min_d = subs(d,t,t1v)
min_d =
1.3577
You can use the following code to generate a figure of illustrating the curve and the distance:
t = [0:0.001:4];
x=5*t-10;
y=25*t.^2-120*t+144;
figure(1);
hold on;
plot(x,y,'b');
axis([0 4 0 4],'square');
x=5*t-10;
d=(x.^2+y.^2).^.5;
figure(1);
hold on;
plot(x,d,'g');
t=t1v;
x=5*t-10;
y=25*t.^2-120*t+144;
plot(x,y,'r.');
plot([0 x],[0 y],'r');
plot([x x],[0 4],'--');