MacRumors Forums help with matlab beginner
 User Name Remember Me? Password

 Thread Tools Search this Thread Display Modes
 Sep 5, 2006, 01:38 PM #1 twoodcc macrumors P6     Join Date: Feb 2005 Location: Right side of wrong 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 in-class 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 __________________ tville Smarter than the average bear 0
 Sep 5, 2006, 01:45 PM #2 notjustjay macrumors 603     Join Date: Sep 2003 Location: Canada, eh? 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, 01:48 PM   #3
twoodcc
macrumors P6

Join Date: Feb 2005
Location: Right side of wrong
Quote:
 Originally Posted by notjustjay 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.

so do i have to tell matlab that it's in km and in km/hour?

and were the commands correct so far?
__________________
tville
Smarter than the average bear
0
Sep 5, 2006, 01:55 PM   #4
Mav451
macrumors 68000

Join Date: Jul 2003
Location: Maryland
Quote:
 Originally Posted by twoodcc the spacecraft also consumes 0.078 liters/hour
Hehe, good thing they give that to you. If they didn't...you probably need to do some dW/dt action in regards to the effects of fuel efficiency as your spacecraft got lighter

In terms of the units--I 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 P55-UD3R | 4GB RAM DDR3 | GTX 580 | 4x 1TB WD | TX750
iPhone 4s (16GB), iBook 800 G3
0
 Sep 6, 2006, 02:27 PM #5 mwpeters8182 macrumors 6502   Join Date: Apr 2003 Location: Boston, MA 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, 02:44 PM #6 balamw Moderator     Join Date: Aug 2005 Location: New England 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, 02:54 PM #7 mkrishnan Moderator emeritus     Join Date: Jan 2004 Location: Grand Rapids, MI, USA 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, 03:01 PM   #8
mduser63
macrumors 68040

Join Date: Nov 2004
Location: Salt Lake City, UT
Quote:
 Originally Posted by balamw (Using MATLAB for this kind of problem seems like overkill. MATLAB truly shines when matrices are involved.) B
Agreed, but the OP said he's in a class to learn MATLAB. I'm sure this is a start-small assignment to get used to syntax, etc.
0
Sep 6, 2006, 03:08 PM   #9
balamw
Moderator

Join Date: Aug 2005
Location: New England
Quote:
 Originally Posted by mduser63 Agreed, but the OP said he's in a class to learn MATLAB. I'm sure this is a start-small assignment to get used to syntax, etc.
I know, but the problem seems so artificial and heavily constrained that it doesn't seem very useful. JMHO.

mkrishnan, I got 18.1E3 liters, which at 1E-3m^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, 03:22 PM   #10
mkrishnan
Moderator emeritus

Join Date: Jan 2004
Location: Grand Rapids, MI, USA
Quote:
 Originally Posted by balamw I know, but the problem seems so artificial and heavily constrained that it doesn't seem very useful. JMHO.
I came up with 18 cubic meters when I knew there were 18k liters, since the liter was already a volumetric unit. But I was wrong about the 2x ... I just knew that 3x3x2=18 and 3x3x3=27. So I think I meant 1.5x.

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 05:40 PM.
0
Sep 6, 2006, 04:21 PM   #11
notjustjay
macrumors 603

Join Date: Sep 2003
Quote:
 Originally Posted by twoodcc thank you for your reply. so do i have to tell matlab that it's in km and in km/hour? and were the commands correct so far?
I didn't actually check your commands closely but at first glance they look like they should work. There might be some minor tweaking but I think you'll get the idea.

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, 05:28 PM #12 twoodcc Thread Starter macrumors P6     Join Date: Feb 2005 Location: Right side of wrong 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 __________________ tville Smarter than the average bear 0
Sep 6, 2006, 06:57 PM   #13
balamw
Moderator

Join Date: Aug 2005
Location: New England
Quote:
 Originally Posted by twoodcc 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.
Ah, a bit more interesting, but it seems like you have still left out some details, since at 1/2 speed, you'd still only be able to go to 6666 km on 50 l of fuel. Not quite all the way to Pluto.

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, 07:22 PM   #14
mkrishnan
Moderator emeritus

Join Date: Jan 2004
Location: Grand Rapids, MI, USA
Quote:
 Originally Posted by balamw Ah, a bit more interesting, but it seems like you have still left out some details, since at 1/2 speed, you'd still only be able to go to 6666 km on 50 l of fuel. Not quite all the way to Pluto.
I think it was liters per hour but km per second, so there was a factor of 3600 involved...

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, 07:34 PM #15 twoodcc Thread Starter macrumors P6     Join Date: Feb 2005 Location: Right side of wrong the teacher told me that he basically just made this up. it might not make it to Pluto. i'm pretty sure i gave all the information __________________ tville Smarter than the average bear 0
Sep 6, 2006, 07:51 PM   #16
deepy
macrumors regular

Join Date: Jun 2006
Quote:
 Originally Posted by twoodcc the teacher told me that he basically just made this up. it might not make it to Pluto. i'm pretty sure i gave all the information
lol. wish we got given problems like this to teach us Matlab. We started with numerical linear algebra and tryin to make matrix calculations more efficient!
0
Sep 6, 2006, 09:02 PM   #17
twoodcc
macrumors P6

Join Date: Feb 2005
Location: Right side of wrong
Quote:
 Originally Posted by deepy lol. wish we got given problems like this to teach us Matlab. We started with numerical linear algebra and tryin to make matrix calculations more efficient!
well i'm glad i wasn't in that class
__________________
tville
Smarter than the average bear
0
 Sep 7, 2006, 12:07 PM #18 twoodcc Thread Starter macrumors P6     Join Date: Feb 2005 Location: Right side of wrong 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 __________________ tville Smarter than the average bear 0
Sep 7, 2006, 12:47 PM   #19
balamw
Moderator

Join Date: Aug 2005
Location: New England
Quote:
 Originally Posted by twoodcc ok, so tell me if my figures are correct:
They seem fine. As was pointed out I left out the 3600 in my half speed estimate and it's consistent w/yours.

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, 01:25 PM   #20
savar
macrumors 68000

Join Date: Jun 2003
Location: District of Columbia
Quote:
 Originally Posted by twoodcc 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));
Hmm.. I never did any user input with matlab, but at least for the output I think you're going overkill. Matlab will display the result of any operation if that operation does not have a semicolon after it. I'm not using matlab right now, but this is kind of what it looks like:

> 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 on-line help.
__________________
Mehce
0
Sep 7, 2006, 01:50 PM   #21
twoodcc
macrumors P6

Join Date: Feb 2005
Location: Right side of wrong
Quote:
 Originally Posted by balamw They seem fine. As was pointed out I left out the 3600 in my half speed estimate and it's consistent w/yours. B
thanks, that's good to know.

now i just gotta put this into matlab
__________________
tville
Smarter than the average bear
0
Sep 7, 2006, 01:51 PM   #22
twoodcc
macrumors P6

Join Date: Feb 2005
Location: Right side of wrong
Quote:
 Originally Posted by savar Hmm.. I never did any user input with matlab, but at least for the output I think you're going overkill. Matlab will display the result of any operation if that operation does not have a semicolon after it. I'm not using matlab right now, but this is kind of what it looks like: > 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 on-line help.
thanks. i just thought i'd post this here for the first assignment so i could get a little extra help outside of class.

hopefully i'll get the hang of it soon
__________________
tville
Smarter than the average bear
0

 MacRumors Forums

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 Similar Threads thread Thread Starter Forum Replies Last Post fahad5022 Mac Applications and Mac App Store 2 Oct 19, 2013 06:03 PM MacNoobGuy Mac Basics and Help 3 Sep 24, 2013 12:15 PM dukebound85 Mac Programming 11 Jun 20, 2013 07:14 PM rokusho1 Mac Basics and Help 2 Nov 8, 2012 06:19 PM iRyu Mac Programming 12 Oct 23, 2012 01:08 PM

 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News and Article Discussion     MacRumors.com News Discussion     Mac Blog Discussion     iOS Blog Discussion iPhone, iPod, iPad, Apple Watch     iOS         iOS 8         iOS 7         iOS 6         iOS 5 and earlier         Jailbreaks and iOS Hacks     iPhone         iPhone Tips, Help and Troubleshooting         iPhone Accessories         iPhone Launch Meetups         iPhone Wallpapers etc.         iPhone Apps     iPad         iPad Tips, Help and Troubleshooting         iPad Accessories         iPad Launch Meetups         iPad Wallpapers etc.         iPad Apps     iPod touch         iPod touch Hacks         iPod touch Accessories         iPod touch Apps     iPod     Apple Watch         Apple Watch Accessories         Apple Watch Apps     Alternatives to iOS and iOS Devices Apple Applications     iPhone and iPod touch Apps     iPad Apps     Apple Watch Apps     Mac Applications and Mac App Store Apple Hardware     Desktops         iMac         Mac Pro         Mac mini     Notebooks         MacBook         MacBook Pro         MacBook Air     PowerPC Macs     Apple TV and Home Theater     Mac Peripherals     Buying Tips and Advice Apple Systems and Services     Mac Basics and Help     OS X         OS X Yosemite (10.10)         OS X Mavericks (10.9)         OS X 10.8 Mountain Lion         Mac OS X 10.7 Lion         Mac OS X Server, Xserve, and Networking     iCloud and Apple Services     Windows, Linux & Others on the Mac     Programming         iPhone/iPad Programming         Mac Programming         App Store Business, Legal and Marketıng Special Interests     Mac and PC Games         Console Games     Digital Audio     Visual Media         Design and Graphics         Digital Photography         Digital Video         Web Design and Development     Apple Collectors     Distributed Computing Mac Community     Community Discussion         Apple, Industry and Internet Discussion         Current Events         Politics, Religion, Social Issues     Picture Gallery         UI Customization     Site and Forum Feedback         Mac Guides Private Forums Archive     Wasteland     Archives of Old Posts         MacRumors News Discussion (archive)         MacBytes.com News Discussion         Buying Tips, Advice and Discussion (archive)         Community         Daily Tunes Site Discussion and Feedback         Event Archives             Macworld San Francisco 2008         Games         General Mac Discussion         Hardware Rumors         iPhone Purchaser Meetups         Leopard Event Meetups         Mac Help/Tips         Mac OS X 10.3 (Panther) Discussion         Mac Scene         Macintosh Computers         MacRumors Old Skool         Marketplace Archive 1 (Posts count)         Marketplace Archive 2             iPhone Marketplace Archive         Music Discussion         New Mac Application Announcements         Product Recommendations/Reviews         Site News         Switch Stories         Web Design and Development (archive)         Past Contests             1,000,000 Post Contest             2,000,000 Post Contest             3,000,000 Post Contest             4,000,000 Post Contest             5,000,000 Post Contest             Ten Million Post Contest

All times are GMT -5. The time now is 04:10 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps
 Contact Us - MacRumors Forums - Archive - Privacy Statement / DMCA Agent - Top

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC