본문으로 건너뛰기
Hub Nexus
업데이트됨

작성자아직 작성자가 없습니다맡기

개선할 점이 보이나요? 변경을 제안하세요.

후원

이 페이지는 공개 상태입니다.

Introduction

MATLAB is interesting in that it is dynamically compiled. In other words, when you're using it, you won't run all your code through a compiler, generate an executable, and then run the executable file to obtain a result. Instead, MATLAB simply goes line by line and performs the calculations without the need for an executable.

Partly because of this, it is possible to do calculations one line at a time at the command line using the same syntax as would be used in a file. It's even possible to write loops and branches at the command line if you want to. Of course this would often lead to a lot of wasted efforts, so doing anything beyond very simple calculations, testing to see if a certain function, syntax, etc. works, or calling a function you put into an .m file should be done within an .m file.

Examples

MATLAB can perform the functions of a simple calculator from the command line. We go thru some of the common Maths problem in the real life.

Here are few of mathematics problem that are demonstrated to be solved in MATLAB:

Painting Coverages

A home painter at work

(Image: E. Stanley Ukeni, CC BY-SA 4.0)

A house painter usually uses 10L of white paint to cover 120 square meter on average for single layer of coating.

Calculate how many 10L paint cans that house painter needed to buy to paint a room with size of 13m X 9m with height 5m from floor to ceiling.

Also the room have 2 windows with size of 1.5m0.75m and 2m1.25m and a door with size of 1.2m*3m

>> room_area=1395 %calculating the overall area of wall for the room

room_area =
585

>> window_area=(1.0.75)+(21.25)

window_area =
3.2500

>> door_area=1.2*3

door_area =
3.6000

>> paint_area=room_area-window_area-door_area

paint_area =
578.1500

>>%amount of paint can needed
paint_area / 120

ans =
4.8179
%house painter needed equaivalent of 5 tin cans to paint the room

Earth to Sun Distance

Naturalis Biodiversity Center - Museum - Exhibition Earth 03 - Sun-Earth model, tilt earth, seasons

(Image: Henk Caspers/Naturalis Biodiversity Center, CC BY-SA 3.0)

Distances from sun to earth is equivalent to 150 million km (150,000,000 km)

If human launched a advance rocket capable of achieving constant speed of 7km/s (ignore all of the air frictions, gravitational pull) , how many year(s) does the rocket to reach the sun from earth ?

>> distance = 150000000

distance =
150000000

>> speed = 7

speed =
7

>> time = distance / speed

time =
2.1429e+07

>> time_to_reach_sun=time/(360024365) % 3600= 1 hour =3600secs, 1 day = 24hour, 1 year=365days(discounting leap years)

time_to_reach_sun =
0.6795

Dice Roll for board games

Double-six-dice

(Image: Joy Shrader, CC0)

You invite some friends come over to play a board game but somehow the dice that should be comes with board game is missing. Create a MATLAB programs to throw two dices (with 6 faces)

You need to use randi command to generate random numbers. More command can be learnt here: MATLAB Programming/Fundamentals of MATLAB/MATLAB operator

>> diceroll = randi(6) + randi(6) % press up button to recall last command and press Enter

diceroll =
9

>> diceroll = randi(6) + randi(6)

diceroll =
6

>> diceroll = randi(6) + randi(6)

diceroll =
9

>> diceroll = randi(6) + randi(6)

diceroll =
11

>> diceroll = randi(6) + randi(6)

diceroll =
5

>> diceroll = randi(6) + randi(6)

diceroll =
12

External Resources

ControlTheoryPro.com

Where this page came from

This page was imported from Wikibooks. From “MATLAB Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

이 페이지가 속한 매거진MATLAB Programming

언어English

이용 허락: CC BY-SA 4.0 · 출처 en.wikibooks.org

견해

코멘트

Spinner Logo
버전: 2CC0 1.0 (퍼블릭 도메인)
The runaway star that left the Tarantula Nebula
버전: 2CC0 1.0 (퍼블릭 도메인)
The Eagle Nebula, seen in the infrared
버전: 2CC0 1.0 (퍼블릭 도메인)
The Cosmic Cliffs are not cliffs
버전: 2CC0 1.0 (퍼블릭 도메인)
The recommended targets are real, but the largest health gain is between doing nothing and doing a little. That is the part worth knowing if you are starting from nothing.
버전: 2CC0 1.0 (퍼블릭 도메인)
Sleep is not one state but a cycle through several, each doing different work. Most sleep disorders are a failure to complete that cycle rather than a shortage of hours.
버전: 2CC0 1.0 (퍼블릭 도메인)
Four nebulae that revealed the shape of our galaxy