Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file...

4
Matlab tutorial course Exercises 1:

Transcript of Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file...

Page 1: Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file ‘startup.m’ and save it in your MATLAB home folder – Must be directly.

Matlab tutorial course

Exercises 1:

Page 2: Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file ‘startup.m’ and save it in your MATLAB home folder – Must be directly.

Exercises• Go back to my webpage, download the file ‘startup.m’ and save it

in your MATLAB home folder– Must be directly in ‘Documents/MATLAB’ (not in the TutorialSlides you

created earlier)

• In your Matlab home folder, create a folder ‘code’• Inside this, create two folders: ‘scripts’ and ‘functions’• Close Matlab, then reopen it

– You should see a welcome message this time (and every time you open Matlab from now on)

– You can edit ‘startup.m’ to change the welcome message if you like– Type ‘path’ in the command window, your folder should have been added

• Copy ‘my_first_script’ and ‘my_fun’ into the suitable folders– Check both script and functions work as before

Page 3: Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file ‘startup.m’ and save it in your MATLAB home folder – Must be directly.

Exercises

• Use Matlab to work out how many seconds there are in a year– Hint, create variables, num_days, num_hours, etc first…– How many seconds are there in 2 years? Or 31 years?

• Can you write this as a function to compute the number of seconds for any given number of years?– Hint your function should have one input (the number of years) and

one output – the answer– Remember to use expressive function and variable names!

Page 4: Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file ‘startup.m’ and save it in your MATLAB home folder – Must be directly.

Exercises• Lookup ‘Newton's law of universal gravitation’ (yes, you can use

wikipedia)• Use the command prompt to compute the force of attraction between

the moon and the earth– You can assume

• Earth’s mass: 5.97x1024 kg• Moon’s mass: 7.35x1022 kg• Distance from earth to moon: 380,000km• Gravitational constant: 6.674×10−11 N m2 kg−2

• Rewrite this as a function that takes as input, M1, M2 and r

• When you have tried both exercises, go back to my website, in the folder ‘code’ then ‘functions’ you can see my sample answers– How did you do?