필터 지우기
필터 지우기

How do I go about plotting points from ODE45 with this?

조회 수: 1 (최근 30일)
Ethan Wong Yew Hoe
Ethan Wong Yew Hoe 2020년 8월 5일
편집: J. Alex Lee 2020년 8월 5일
I have been trying to use ODE45 to solve the linearised model, my aim is to plot values of y and x displacement but the code does not seem to churn out any right answers. The attached images are the equations I am given to work around with. Are my ODE45 parameters wrong? Any advice would help a lot!
my function is as follows
function dydx = odefcn(x, y, a, v)
dydx = zeros(2, 1);
dydx(1) = y(2);
dydx(2) = a/v^2;
%========================= MAIN CODE ===========================%
% Get launch angle (theta) from user, then get initial x and y coordinates
% Constants are VELOCITY (v), N, DESIGNATED TIME (Td)
% Variables are x and y
% LOS, a, L are always changing, so need to INCLUDE THEM IN A LOOP
% Output will be x and y, ALSO ALWAYS CHANGING
%======================= Get input from user =============================%
theta0 = input('Please input launch angle in degrees: ');
x0 = input('Please enter initial x coordinates: ');
y0 = input('Please enter initial y coordinates: ');
%=========================== Constants ===================================%
v = 300;
N = 3; % Proportionality constant
Td = 40; % designated impact time
targetx= 50; targety = 50; % set targetcoordinates
Rgo_x = targetx - x0;
Rgo_y = targety - y0;
theta = theta0;
xspan = [x0 targetx];
yspan = [y0 targety];
IC = [0 theta0];
x=x0; y=y0;
while Rgo_y ~= 0 & Rgo_x ~= 0
Rgo = sqrt(Rgo_x^2 + Rgo_y^2);
LOS = -(Rgo_y/(Rgo^2));
Tgo = (1+ (theta-acosd(Rgo_x/Rgo))/10)*(Rgo/v);
a = N*v*LOS - (60*v^5*(Td-Tgo))/(N*v*LOS*(Rgo^3));
theta = a*(Rgo_x)/v^2 + theta;
[x, y] = ode45(@(x, y)odefcn(x, y, a, v), xspan, yspan, IC);
Rgo_x = targetx - x;
Rgo_y = targety - y;
end
%================ Plot x and Y values wrt to angle changes ===============%
figure
grid on
plot(x, y, 'o')
xlabel('x displacement (m)');
ylabel('y displacement (m)');

답변 (1개)

J. Alex Lee
J. Alex Lee 2020년 8월 5일
yes, your odefun looks wrong, it looks like you did not correctly apply matrix algebra to get the separate equations from your matrix form.
And why aren't there 2 a's, aB and aF?
  댓글 수: 2
Ethan Wong Yew Hoe
Ethan Wong Yew Hoe 2020년 8월 5일
Oh my bad! there is a given expression for a=aB + aF
where a = N*v*LOS - (60*v^5*(Td-Tgo))/(N*v*LOS*(Rgo^3));
Td is a constant, Tgo is Rgo_x, Rgo and theta dependent (see line 41-43)
Is my ODEfcn making any sense though?
J. Alex Lee
J. Alex Lee 2020년 8월 5일
편집: J. Alex Lee 2020년 8월 5일
i apologize, it must have been early in the morning, your odefcn does look ok.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by