Thread Subject: Problem with function

Subject: Problem with function

From: Nemal

Date: 3 Nov, 2009 19:00:21

Message: 1 of 1

Hi there,
I am writing a small script to generate some values regarding my homework. All the values in these function should be a integer. Somehow, the y function ends up giving a matrices as an answer. But when i manually type out the values and calculate, it turns out to be an integer. I am lost as I dont know where am i going wrong? Please help me out

**********************************************************
%Universal Variable
GP = 398600;

r1_v = [5644 -2830 -4170]; %in km
r2_v = [-2240 7320 -4980];

delta_t = 20/60; %in hrs

r1 = norm(r1_v);
r2 = norm(r2_v);

% assuming prograde trajectory

check = cross(r1_v, r2_v);

%to determine the delta theta
if check(3) > 0
    delta_theta = acosd((dot(r1_v, r2_v))/(r1*r2));
else
    delta_theta = 360 - acosd((dot(r1_v, r2_v))/(r1*r2));
end

A = sind(delta_theta) * sqrt((r1*r2)/(1-cosd(delta_theta)));

% to determine where F(z) becomes zero starting from -100
z=0.1
% to calculate the exact z
ratio = 1;
while abs(ratio) >1e-8
    ratio=F(z, delta_t)/DF(z)
    z = z- ratio;
end

%calculation of lagrange coefficients
f = 1 - y(z)/r1;
g = A * sqrt(y(z)/GP);
gdot = 1 - y(z)/r2;

% calculation of velocity
v1_v = 1/g*(r2_v-f*r1_v)
v2_v = 1/g*(gdot*r2_v-r1_v)

*******************************************************
%Subfunctions

function calcF_zt= F(z, delta_t)
    global GP A
    calcF_zt = ((y(z)/C(z))^1.5)*S(z) + A*sqrt(y(z))-sqrt(GP)*delta_t;
return

function y=y(z)
    global r1 r2 A
    y=r1+r2+A*((z*S(z))-1)/sqrt(C(z));
return

function stumpS = S(z)
    if z > 0
        stumpS = (sqrt(z)-sin(sqrt(z)))/(sqrt(z))^3;
    elseif z<0
        stumpS = (sinh(sqrt(-z)) -sqrt(-z))/(sqrt(-z))^3;
    else
        s = 1/6;
    end
return

function stumpC = C(z)
    if z > 0
        stumpC = (1-cos(sqrt(z)))/z;
    elseif z<0
        stumpC = (cosh(sqrt(-z))-1)/(-z);
    else
        stumpC = 1/2;
    end
return

function Df = DF(z)
    global A
    if z == 0
        Df = sqrt(2)/40 * y(0)^1.5 + A/8*(sqrt(y(0))+A*sqrt(1/2/y(0)));
    else
        Df = (y(z)/C(z))^1.5*((1/(2*z))*(C(z)-1.5*(S(z)/C(z))) + 0.75 * (((S(z))^2)/(C(z)))) + (A/8)*(3*(S(z)/C(z))*sqrt(y(z))+A*sqrt(C(z)/y(z)));
    end
return

********************************************
i have a feeling there is something wrong at my y function

>> y(2)

ans =

     []

r1+r2+A*((z*S(z))-1)/sqrt(C(z))

ans =

  8.6168e+003

can someone help me out??

Thanks
Nemal

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com