Got a tip for us? Let us know
Sep 5, 2006, 02:38 PM  #1 
help with matlab beginner
i'm currently taking a matlab course. i've never used matlab before, so it's very new to me.
we had an inclass assignment today, that we didn't have time to finish, but i am stuck. we have information that Pluto is 4.34 billion km from earth. we have a spacecraft that travels at 5.2 km.sec the spacecraft also consumes 0.078 liters/hour will it have enough fuel to reach pluto? that is the assignment basically. here is what i have done so far: distance = input('How far away is Pluto in km? '); fuel = input('How much fuel in liters does the spacecraft have? '); speed = input('How fast does it go? '); disp(sprintf('Pluto is %5.2f km away from the Earth.', distance)); disp(sprintf('The spacrecraft has %5.2f liters of fuel,' fuel)); am i doing this right? any help will be greatly appreciated thanks in advance 

0 
Sep 5, 2006, 02:45 PM  #2 
Well, Matlab is a very powerful tool, but at heart it's basically a calculator
What you should do first is get a handle on how to solve the actual math problem first. You can maybe write it down on paper, use variable names you're familiar with. With this problem, for example, you're going to need to convert some units around (km/sec into km/hour) and do some intermediate steps (how many hours will it take to fly to Pluto?). Once you figure out the steps, writing them into a Matlab .m file is almost as simple as writing them down on paper, step by step.
__________________
. 

0 
Sep 5, 2006, 02:48 PM  #3  
Quote:
so do i have to tell matlab that it's in km and in km/hour? and were the commands correct so far? 

0 
Sep 5, 2006, 02:55 PM  #4  
Quote:
In terms of the unitsI think that is inherent in the constants you put in. E.g. Calculate everything in km/sec. And then at the end, put a few lines that will convert it back to km/hour...basically your "km/sec" value * 3600 (hr/min * min/sec)
__________________
i5 @ 3.6 Ghz  GB P55UD3R  4GB RAM DDR3  GTX 580  4x 1TB WD  TX750 iPhone 4s (16GB), iBook 800 G3 

0 
Sep 6, 2006, 03:27 PM  #5 
Since you're using matlab, the best way (if they've taught this yet) is to use a function. That way you don't have to worry about the prompt every time you run the program.
You could run it as pluto(distance, amount of fuel), and it could return yes/no. Otherwise, I agree with the rest of the folks in here. Run the calculations out by hand, and then code them.
__________________
2.0 GHz Aluminum MacBook iPhone 3G 

0 
Sep 6, 2006, 03:44 PM  #6 
All I can say is d*mn that's a lot of fuel!
If the fuel is as dense as water it would weigh 18 metric tons and fit in a 3x3x3 meter cube. (Using MATLAB for this kind of problem seems like overkill. MATLAB truly shines when matrices are involved.) B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme 

0 
Sep 6, 2006, 03:54 PM  #7 
LOL You're just lucky the spaceship doesn't travel at relativistic speeds!
But psssh...why is it burning fuel all the way to Pluto? Shouldn't it be doing an initial burn and holding onto its fuel for positioning when it gets to the planet? There's not exactly a lot of wind resistence out there! The 3x3x3 doesn't seem quite right. It seems too big by a factor of two, unless *I'm* miscalculating.
__________________
Mira C. Krishnan 

0 
Sep 6, 2006, 04:01 PM  #8  
Quote:
__________________
27" 2.93 GHz Core i7 iMac, 12 GB RAM 2.3 GHz Retina MacBook Pro 12" 1.33 GHz Superdrive PowerBook G4, 1.25 GB RAM iPhone 5, iPad 3, etc. 

0 
Sep 6, 2006, 04:08 PM  #9  
Quote:
mkrishnan, I got 18.1E3 liters, which at 1E3m^3/l works out to 18.1 m^3, the cube root of 18.1 is 2.62, so I rounded up a bit to 3. Did I screw it up somewhere! (You're right, that the volume increase from my rouning almost doubles it, but I suspect you'd need some wall thickness to contain the fuel. ) B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme 

0 
Sep 6, 2006, 04:22 PM  #10  
Quote:
Hehehehehehe But yeah, this is a weird problem to use Matlab for because it's so clearly suited to a simple calculator. (EDIT: 18k liters natch )
__________________
Mira C. Krishnan Last edited by mkrishnan; Sep 6, 2006 at 06:40 PM. 

0 
Sep 6, 2006, 05:21 PM  #11  
Quote:
As for telling matlab that it's in km and km/hour  not exactly. You  the programmer  need to keep track of your units. (I don't mean to sound condescending or anything, so I apologize if I do, I really have no idea what level of math this is (high school? college?), so I have to appeal to the lowest common denominator I also don't want to give away the answer directly, so excuse me for being a bit obtuse at times too.) Forget all about Matlab for the moment, and suppose you are trying to solve this problem with a paper and pencil. You need to work through the exact steps first. THEN you can worry about whether or not the code is correctly performing these steps. In fact, this is how you would "unit test" your code once you get it done  you calculate your answer by doing it by hand, and then run your code. If your code produces the same answer, then you know you coded it correctly. So, given: fuel_consumption = 0.078 liters/hour distance = 4.34 billion km speed = 5.2 km/sec fuel_provided = (user provided) liters In order to answer "will it have enough fuel", you first need to ask "how much fuel will it need?" Ultimately you want to compare: is fuel_provided >= fuel_needed? So how do you calculate fuel_needed? You need to know the fuel consumption rate (which is given) and how long the spacecraft will be burning fuel (time). OK, so now you need to calculate how much time the spacecraft will be travelling for. How do you do that? You'll need to know the distance (given) and speed (given). But your distance is in km's per hour and your speed is in km's per second. How do you convert km's per second into km's per hour? ... and so it goes. Break it down into little steps. Your steps on paper should look like this: 1. Convert speed from km/sec to km/hour 2. Time = ??? 3. Fuel_needed = ??? 4. Is fuel_provided > fuel_needed? Then you can write Matlab code to get the data from the user, do the calculation, and print the answer.
__________________
. 

0 
Sep 6, 2006, 06:28 PM  #12 
thanks for the replies and help. this is a college course, and i'm actually taking visual basic as well (about to go to class soon)
anyways, i forgot a few details in the problem, if you would like to know. you have 50 liters of fuel in the tank to start off with, and the second part of the problem is: the spacecraft cosumes 1/4 of fuel when going 1/2 the speed. sorry i can't say more, but i gotta eat then get to class. thanks 

0 
Sep 6, 2006, 07:57 PM  #13  
Quote:
Perhaps if the fuel consumption continues to scale like the square of the speed you might be able to get there at super slow speed. B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme 

0 
Sep 6, 2006, 08:22 PM  #14  
Quote:
Okay, okay, I just miss being an engineer once in a while. sosumi. But I think there are pieces of data missing. I don't see how this is going to happen on 50l of fuel!
__________________
Mira C. Krishnan 

0 
Sep 6, 2006, 08:51 PM  #16  
Quote:


0 
Sep 6, 2006, 10:02 PM  #17  
Quote:


0 
Sep 7, 2006, 01:07 PM  #18 
ok, so tell me if my figures are correct:
5.2 * 3600 = 18720 km/hr 50/.078 = 641.025641 hrs 18720 * 641.025641 = 12,000,000 km  didn't make it to Pluto 18720 / 2 = 9360 .078 / 4 = .0195 50 / .0195 = 2564.102564 hours 9360 * 2564.102564 = 24,000,000  didn't make it to pluto 

0 
Sep 7, 2006, 01:47 PM  #19  
Quote:
B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme 

0 
Sep 7, 2006, 02:25 PM  #20  
Quote:
> a = [1 2; 3 4] a = [1 2 3 4] > b = [1 2; 3 4]; > Without semicolon, Matlab shows you the result of the operation (in this case, the operation is merely assignment). With semicolon, matlab does not show the result. Matlab is amazingly powerful but so different from any other environment that I've ever used. I suggest you attend as many extra hours sessions as possible (office hours, labs, whatever it is they offer) if you're interested in Matlab. I learned far more watching somebody else use it than I ever could have with the online help.
__________________
Mehce 

0 
Sep 7, 2006, 02:51 PM  #22  
Quote:
hopefully i'll get the hang of it soon 

0 
«
Previous Thread

Next Thread
»
Thread Tools  Search this Thread 
Display Modes  
Similar Threads  
thread  Thread Starter  Forum  Replies  Last Post 
matlab for mac  fahad5022  Mac Applications and Mac App Store  2  Oct 19, 2013 07:03 PM 
Matlab 2013: What can it be used for?  MacNoobGuy  Mac Basics and Help  3  Sep 24, 2013 01:15 PM 
Matlab interpolation  dukebound85  Mac Programming  11  Jun 20, 2013 08:14 PM 
Matlab help  rokusho1  Mac Basics and Help  2  Nov 8, 2012 07:19 PM 
Matlab, Java, C++ ?  iRyu  Mac Programming  12  Oct 23, 2012 02:08 PM 

All times are GMT 5. The time now is 03:12 AM.