• 100% Satisfaction Guarantee
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7677
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
44910485
ATLPROG is online now

# I have a code which is 50% done and would like to finish the

### Customer Question

I have a code which is 50% done and would like to finish the rest of.
Submitted: 7 months ago.
Category: Programming
Expert:  LogicPro replied 7 months ago.

Hi

Customer: replied 7 months ago.
The question to come up with a code the can calculate the Centre of gravity (CoG) of an A320 aircraft.
The teacher told me to write a code that can calculate and track where the centre of gravity is and how it changes with respect to time.
I am using 30*7 matrices to simulate the seating of passengers in the aircraft. I need to find the CoG in the horizontal and vertical way. If can finish the code off or you can write a new code that would be nice because I am to Matlab and I need urgent help.
I and the teacher have started the code as seen below:
airlineRows = 30;
airlineHalfSideSeats = 3;
occupancyFactor = 0.85;
% Create a seat map of the left side, middle asile, and right side.
rightSide=rand(airlineRows, airlineHalfSideSeats) < occupancyFactor;
middleAisle=zeros(30,1);
leftSide=rand(airlineRows, airlineHalfSideSeats) < occupancyFactor;
% Now make a seat map for the entire plane by combining them.
passengerMap = [rightSide, middleAisle, leftSide]
[rows, columns] = size(passengerMap)
% Make passenger weights uniformly distributed between 67 and 87:
passengerWeights = 67 + 20 * rand(size(passengerMap))
% Make passenger carry-on luggage weights uniformly distributed between 6 and 8:
luggageWeights = 6 + 2 * rand(size(passengerMap))
% Zero out empty seats.
passengerWeights = passengerWeights .* passengerMap
luggageWeights = luggageWeights .* passengerMap
timePoint = 1;
for row = 1 : rows
% First assume that the left side empties first.
for col = 3 : -1 : 1
passengerMap(row, 3) = 0; % Empty the aisle seat only, seat #3.
% Update passenger weight and luggage weight.
passengerWeights = passengerWeights .* passengerMap
luggageWeights = luggageWeights .* passengerMap
% That passenger is now gone.
% Remaining passengers shift to the right
% See if you can figure out how to shift the arrays to the right.
; % Code.....
% After the aisle passenger has left, and remaining passengers
% has shifted right, re-compute center of gravity.
% I'll let you do this. Let us know if you can't figure it out.
[xCOG(timePoint), yCOG(timePoint)] = FindCOG(passengerMap, passengerWeights, luggageWeights)
timePoint = timePoint + 1;
end
% Now empty the right side.
% Start with seat in column 5, then 6, and then finally 7
for col = 5 : 7
passengerMap(row, 5) = 0; % Empty the aisle seat only, seat #5.
% Update passenger weight and luggage weight.
passengerWeights = passengerWeights .* passengerMap
luggageWeights = luggageWeights .* passengerMap
% That passenger is now gone.
% Remaining passengers shift to the left
% See if you can figure out how to shift the arrays to the left.
; % Code.....
% After the aisle passenger has left, and remaining passengers
% has shifted left, re-compute center of gravity.
% I'll let you do this. Let us know if you can't figure it out.
[xCOG(timePoint), yCOG(timePoint)] = FindCOG(passengerMap, passengerWeights, luggageWeights)
timePoint = timePoint + 1;
end
end
Expert:  LogicPro replied 7 months ago.

Which programming language you are using?

Customer: replied 7 months ago.
I am using Matlab. But I am new to Matlab.
Expert:  LogicPro replied 7 months ago.

My apologies, I am out of ideas for matlab and opting out for other Professionals to answer. Please wait. You will be notified by email as soon as any Professional joins you.