GUIs and other fun stuff
Lecture Week 11
Limitations of Arrays
Arrays can contain
Arrays must be rectangular
Every row has same number of columns
Every column has same number of rows
So you cant have
Numbers
Characters
['hello'; 'goodbye']
You cant have
[
CS100: Quiz # 3
Time: 15min
Q-1 [4 marks]
You get into LUMS and to celebrate you decide to throw a party for all your friends.
Because you dont have enough money you only get one z inch (radius) pizza.
Assuming you invited an n number of friends, write MA
CS100 - Quiz 5 16/10/2015 30 minutes
Summary: You have to animate a ball following a projectile motion, which loses speed each
time the ball hits the floor.
Write a program which draws a circle (2 marks) of diameter 10, color red, and starting position
(0
Quiz 8
Roll No:
Time: 20min
Name:
Marks: 20
Q1. What is the output when I enter the following line of code in the command window [10 marks]:
> iftari(5)
function iftari(time)
if time=5
a = 1; b = 4; m = 3; p = 3; g = 15;
plate=fruitchaat(a,b,m,p,g);
for i
Quiz 8
Roll No:
Time: 20min
Name:
Marks: 20
Q1. What is the output when I enter the following line of code in the command window [10 marks]:
> iftari(5)
function iftari(time)
if time=5
a = 1; b = 4; m = 3; p = 3; g = 15;
plate=fruitchaat(a,b,m,p,g);
for i
Quiz 8
Roll No:
Time: 30min
Name:
Marks: 20
Q1. What is the output when I enter the following line of code in the command window [10 marks]:
> iftari(5)
function iftari(time)
if time=5
a = 1; b = 4; m = 3; p = 3; g = 15;
plate=fruitchaat(a,b,m,p,g);
for i
CS100 - Quiz 5 16/10/2015 15 minutes
Write a program which draws a circle (2 marks) of diameter 10, color blue, and starting position
(0,0) inside a window (2 marks) of size 250 by 250. There should be a single for loop which runs
for N iterations (where
Recitation 2
Solution (next page)
Q1-Write a single MATLAB expression to generate a vector that contains first 100 terms of
the following sequence:
2, -4, 8, -16, 32, .
Q2-What is the value of y at the end of this program?
x = [13 4 7 11 8 3 9 4 2]
y = [x
Recitation 1
Solution
Q1- Which variable names are valid / invalid / valid-but-may-cause-errors? Give reasons.
1. Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab
Matlab allows 71 character variables so may cause errors
2. Aaaaaaaaa
Recitation 5
Solution
Q0) What does the following code display: cfw_ans: -5
s = 10;
for x = 2:3:15
if x <= 8
s = s - x;
end
end
disp(s)
Q1) What does the following code display: cfw_ans: 2 4 6 8 10
for i=1:10
if(mod(i,2)=1)
continue;
end
disp(i);
end
Q2)
Recitation 4
Solution (next page)
Q1. What is the value of x after the following program is run?
x= [ ];
for i = 1 : 4
x = [x 3];
end
Q2. What is the value of A after the following program is run?
A = [ ];
for i = 1 : 4
A = [ A numel(A)*2 sum(A) ];
end
Q3
Recitation 6
Solution
Q1-What is the value of Y at the end of the program?
1. y = 1+3>4
2. y = 2*3:8>7
3. y = 'L'<50 (ASCII value of K is 75)
cfw_ans = 0
cfw_ans = 0 0 1
cfw_ans = 0
Q2-What is the value of s at the end of the following execution?
x = ones
Variables, Expressions and
Assignment Statements
Lecture 2
Variables
A symbolic name given to some quantity,
associated with a memory storage location
NAME
CS 100 | Fall 2013 | Lecture 2
VALUE
[may change over time]
Variables
NAME VALUE
MEMORY
CS 100 | F
Kinds of Loops
Lecture Week 4
Kinds of Loops
Ignore the index
common
moderate
Use a variable that get
changed in every loop
common
Use several formulas of
the index
Use an array to get an
arbitrary sequence (no
simple formulas)
simple
Use a formula calcul
Vectors and More
Lecture 4
Comparison Operators
<, >, <=, >=, =, ~=
TRUE is 1
FALSE is 0
For what values of x is
this statement TRUE?
3<x<5
First 3 < x is either TRUE
(1) or FALSE (0)
0 < 5 is TRUE
1 < 5 is TRUE
So ALWAYS TRUE
What does this
compute?
(x >
2D and 3D Graphics
Lecture Week 12
Making Images Move
How can we
make such an
animation?
One image
moving across
another
image
Making Images Move
An image is an object just like the rectangle
Has a handle, and properties that can be changed
Example settin
CS 100 Practice Problem - Tic-Tac-Toe
The problem name says it all. Make a simple tic-tac-toe game in MATLAB. You should make a
nice little tic-tic-toe grid in a MATLAB figure using the line command, and then get input from
alternating users using ginput
Lahore University Of Management Sciences
School of Science and Engineering
Total Pages: 11 (including this page)
Roll # :
Quarter: Winter
Academic Year: 20082009
Problem Solving using
Course Title: Comptuters
Course Code: CS 102
Instructor: Sohaib Khan &
Final Examination
CS 102
Spring 2010
Be careful in using the right notation.
Use [ ], or ( ) appropriately where needed.
Do not forget to put dots before operators, where needed.
Follow instructions literally
The programs have all been tested in MATLAB, s
Note: Solution is highlighted with red
Page 2 of 12
1. What would be printed by
a.
b.
c.
d.
e.
2.
0 1 2
0 -1 -2
5
0 1 4
an error
> ([4 3 2] - 4) .^ 2
What is the length of the vector generated by
> [2.718281828459045 : 0.1 : 3.141592653589798]
a.
b.
c.
d.
Introduction
Lecture Week 1
CS 100 | Fall 2015 | Lecture 1
Course Team
Arif Zaman
Professor, Dept of
Computer Science
PhD, Stanford, 1981
Research Interests:
Cryptography, Big Data
Suleman
Shahid
Assistant Professor in
Computer Science
PhD, Tilburg U
Lecture 9: Nested Loops
Lecture 9
Making a square
How to make a square?
Location (x, y) can specify lower-left corner, or center
Size can be specified by giving the length of a side, or a
perimeter.
We could even add a rotation angle.
So we need to make c
More Expressions
Lecture Week 3
CS 100 | Fall 2013 | Lecture 3
Critical Concepts Review
Variable:
a named storage in memory containing some value
think of it as MEMORY button on your calculator, except the
calculator typically has only one. Here, you can
Lecture 6: Conditionals
Lecture 6
Types of Errors and Warnings
Syntax
Caught before
you even start
the program
Look out for
1 and l,
0 and O,
` and
Evaluation
Occur while
running the
program
Division by
zero
Adding
matrices of
different sizes
Logical
Big
Structured Programming
Lecture Week 9
Design Patterns
We have learnt a number of patterns that we re-use
One way to reuse them is to look them up in our old
code, or notes, and then copy/paste them into our
new
A better way is to use M-files
We want to co
The Trains Analogy [15 marks]
One of the major advantages of functions is that they have a completely separate (local) workspace from
the MATLAB (global) workspace. A simple way to view the relationship between the two workspaces is
using the following pi