Problem with Exercise 165 Safe Landing

Back to General discussions forum

Lubecki     2015-09-15 04:08:34

When I use the provided test application and then enter the same values in my program, I get nearly the same results. When I then submit my code for verification, I get considerably different answers.

Rodion (admin)     2015-09-15 05:34:53
User avatar

Hi!

link to your code for convenience

I'm not quite sure, but it seems that your main loop:

public void land(int[] rates) {
    for (int rate : rates) {
        burn(rate);
    }
}

Does not take care of landing the craft if the fuel ends before touchdown - isn't it so?

After the fuel is ended the further settings should be ignored. If after proceeding through all the sequence the rocket still is not on the surface, continue calculation as it is in free fall.

I'm sorry if this part of problem statement looks vague...

Lubecki     2015-09-15 22:47:51
        float deltaFuel = 0;  
        if (fuelMass > 0) {
            deltaFuel = rate * dt;
            if(fuelMass - deltaFuel < 0) {
                deltaFuel = fuelMass;
            }
        }

        float deltaV = EXHAUST_SPEED * deltaFuel / (emptyMass + fuelMass);
        fuelMass -= deltaFuel;

        if(height >= 0) {
            velocity = velocity + (getGravity() * dt) - deltaV;
        } else {
            velocity = 0;
        }

If there is no remaining fuel, deltaFuel is 0, making deltaV 0. As a result it becomes:

velocity = velocity + (getGravity() * dt) - 0f;

Which only takes gravity into account.

Rodion (admin)     2015-09-16 03:38:51
User avatar

>Which only takes gravity into account.

This sounds correct, yes - but I do not see how your formula allows to calculate the change of speed during free fall.

Say, if rates contains only one value, we burn it very soon - and then we still need to calculate many iterations of free fall (and with changing gravity).

However it looks like your loops will stop after processing rates is completed.

Or may be I'm misunderstanding something?

Lubecki     2015-09-16 04:35:28

I see my error. For some reason I had interpreted the answer as the velocity of the ship after the last attempt to burn fuel. I have since added some logic to allow it to fall until it reaches the surface. I appreciate the help.

Christopher Matthews     2015-09-16 12:08:59

Lubecki - Your approach looks very similar to mine; great minds think alike :)

-- Christopher P. Matthews

perevertysh     2018-02-28 20:56:59

Расход топлива секундный в условие добавьте, пожалуйста.

perevertysh     2018-02-28 21:26:11

Вопрос снят. "Rate" в условие упомянуть бы, и единицами обозначить. А то не ясно регулировка тяги в процентах это, или регулировка дросселя в системе подаче топлива в единицах массы.

Please login and solve 5 problems to be able to post at forum