How can I pass a function to the GUIDE?
Show older comments
Good afternoon, I am starting to use GUIDE-MATLAB, I do not have much experience, I need help I have my functions performed in SCRIP, to calculate the trajectory of a reentry vehicle to the Earth's atmosphere, I want to pass the functions to GUIDE, and I have problems with the functions, please help.
My codes.
%==========================================================================
format long
clear all
clc
%==========================================================================
%Input data
V = 8200; %speed at re-entry into the atmosphere MIK-1
Gca = 9500; %macc MIK-1
Cxa = 1.3424; %resistencia MIK-1
Sp = 14; %capsule midsection area MIK-21
K=0.4721; %aerodynamic coefficient MIK-1
%--------------------------------------------------------------------------
rho0 = 1.225; %density at sea level (kg/m3)
%V = 7800; %speed at re-entry into the atmosphere apollo
% V = 9000; %speed at re-entry into the atmosphere orion
H = 100000; %altitude range (meters)
z=0.5;
t = 0:z:900; %time range
% Gca = 8060; %mass apollo
% Gca = 12000; %mass orion
% Cxa = 1.314; %resistance coefficient apollo
% Cxa = 1.3884; %resistencia orion
% Sp = 16; %capsule midsection area apollo
% Sp = 19.9; %capsule midsection area orion
theta = -2; %angle of entry atmosphere
L=1.68; %rango de superficie
%K=0.5; %aerodynamic coefficient apollo
%K=0.5054; %aerodynamic coefficient orion
miu = 3.986e+14; %gravitational parameter of the earth
beta=1.395e-04; %atmospheric density gradient
R3= 6.371*1000000; %earth radius
R=R3+H;
g=miu./R.^2;
Px=Gca/(Cxa*Sp);
%--------------------------------------------------------------------------
f = @(t,y) myderiv(t,y,g,Px,R3,K,rho0,beta);
%--------------------------------------------------------------------------
%Set Initial Conditions
y0(1) = V;
y0(2) = theta;
y0(3) = H;
y0(4) = L;
% y0(5)=K;%
%--------------------------------------------------------------------------
% Allocate state vector matrix and initialize first state
n = numel(t);
y = zeros(4,n);
y(:,1) = y0;
%--------------------------------------------------------------------------
%RUNGE KUTTA 4 ORDER
% z = (t(2) - t(1))/2; % stepsize
for j=1:n-1
k1 = f(t(j) , y(:,j) );
k2 = f(t(j) + z/2, y(:,j) + k1*z/2);
k3 = f(t(j) + z/2, y(:,j) + k2*z/2);
k4 = f(t(j) + z , y(:,j) + k3*z );
y(:,j+1) = y(:,j) + (z/6)*(k1 + 2*k2 + 2*k3 + k4);
end
plot(t,y(1,:) ,'b-', 'LineWidth',2);
grid on
function dydt = myderiv(t,y,g,Px,R3,K,rho0,beta) % added rho0 and beta
V = y(1);
theta = y(2);
H = y(3);
L = y(4);
% K=y(5);%
% got rid of y(5) and y(6) which don't exist
p = rho0*exp(-H*beta); %atmosphere density a function of H
R = R3+H; % you need to fill this in
dVdt = -(g.*sind(theta))-(p.*(V.^2)/(2.*Px));
dthetadt = (p*V*K)/(2*Px)+(V^2-g*R)/(R*V)*cosd(theta); % Need V here, not v
dHdt = V*sind(theta);
dLdt = R3*V*cosd(theta)./(R);
% dn=sqrt(1+K^2)/(2*Px*g)*p*V^2;%
dydt = [dVdt;dthetadt;dHdt;dLdt];
end

Answers (0)
Categories
Find more on Guidance, Navigation, and Control (GNC) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!