0% found this document useful (0 votes)
74 views2 pages

119 Exercises New-Old

This document outlines exercises to be completed using Scilab software as part of a workshop on introduction to Scilab. It includes 9 sections covering various Scilab topics like basic calculations, vectors, matrices, scripts/functions, plotting, conditional branching, iteration, polynomials, and ordinary differential equations. Participants are instructed to solve examples for each topic after watching the corresponding tutorial. The document provides detailed examples to practice a wide range of Scilab capabilities.

Uploaded by

limeares
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views2 pages

119 Exercises New-Old

This document outlines exercises to be completed using Scilab software as part of a workshop on introduction to Scilab. It includes 9 sections covering various Scilab topics like basic calculations, vectors, matrices, scripts/functions, plotting, conditional branching, iteration, polynomials, and ordinary differential equations. Participants are instructed to solve examples for each topic after watching the corresponding tutorial. The document provides detailed examples to practice a wide range of Scilab capabilities.

Uploaded by

limeares
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Workshop: Introduction to Scilab

Funded by the National Mission on Education through ICT


Indian Institute of Technology Bombay, 26 January, 2011
Organised by FOSSEE Group, IIT Bombay, http://scilab.in
(The sequence of spoken tutorials to be listened/followed is same as that of exercise sets below.)
1. Getting Started
Solve the following examples on the Scilab
Console as soon as the relevant topic is ex-
plained in the tutorial.
(a) Perform the following calculations on
the scilab command line:
phi =

5 + 1
2
psi =

5 1
2
Find 1/phi and 1/psi.
(b) Verify Eulers identity: Is e
i
+1 close
to zero?
(c)
4

256
(d) 256
0.25
(e) e
i
(f) tan(45)
(g) tan
1
(1)
2. Vector Operations
Solve the following examples on the Scilab
Console as soon as the relevant topic is ex-
plained in the tutorial.
(a) Dene two vectors A,B with 1,5,8,19
and 19,8,5,1 elements respectively.
Calculate A*B-B*A
Calculate A*A+B*B
(b) In Scilab, enter the following Matri-
ces:
A =

1 1/2
1/3 1/4
1/5 1/6

B =

5 2

, C =

4 5/4 9/4
1 2 3

Using Scilab commands, compute


each of the following, if possible and
explain the errors, if any.
(c) A CC A
(d) 2 C 6 A
(e) (2 C 6 A

) B

(f) (2 C 6 A

) C

3. Matrix Operations
Solve the following examples on the Scilab
Console as soon as the relevant topic is ex-
plained in the tutorial.
(a) If A =

1 1 0
2 3 1
4 1 5

Find A(:, :)
Extract the second column of A
(b) Determine the determinant and eigen-
values of the matrix, A
2
+ 2 A .
(c) Dene a 3x3 matrix A with all ele-
ments equal to 1. Multiply 1st and
2nd row with scalars, 3 and 4 respec-
tively, and determine the determinant
of the resultant matrix.
(d) Represent the following linear system
as a matrix equation. Solve the sys-
tem using the inverse method:
x + y + 2z w = 3
2x + 5y z 9w = 3
2x + y z + 3w = 11
x 3y + 2z + 7w = 5
(e) Try solving the above system using
the backslash method.
(f) Verify the solution from the previous
question.
(g) If A =

2 3 1
4 6 5
1 3 6

Use a suitable sequence of row opera-


tions on A to bring A to upper trian-
gular form.
1
4. Scripts and Functions
Solve the following examples on the Scilab
Console as soon as the relevant topic is ex-
plained in the tutorial.
(a) Create a scilab script le to dis-
play time on console window. (hint:
clock())
1
Upper triangular matrix: all elements below the North-West to South-East diagonal of the matrix are zero.
(b) Create a scilab script le to display
product of a matrix A and inverse of
A. A = [1, 1; 1, 1]
(c) Create a function le to calculate sum
and dierence of any two numbers.
The output should be the sum and the
dierence of numbers.
(d) Create a function le to calculate
the rowwise and columnwise mean
and standard deviation of a user de-
ned matrix. Display the matrix, its
mean and standard deviation in out-
put. (hint; mean(), stdev() )
(e) Create an inline function to sort the
elements of a random vector in de-
scending order. (hint: gsort())
(f) Create an inline function to round o
the elements of a vector [1.9, 2.3, -
1.1, 50.5] to the nearest integer. (hint:
round())
(g) Create a function le to calculate LU
factorization of a matrix. (hint: lu()).
5. Plotting
(a) 01:12: Create a linearly spaced vector
from 0 to 1 with 10 points
(b) 01:12: Also create a linearly spaced
vector from 0 to 1 with 11 points
(c) 01:35: plot sin(x) versus x.
(d) 02:50: Use plot2d and try changing
the color to red. Also try style = -1
(e) 03:53: Put a title: Sine, and labels,
x axis and y axis
(f) 05:50: Plot sin(x) and cos(x) on the
same window.
(g) 06:08: Create a legend for the above
plots.
(h) 09:25: Now plot sin(x) and cos(x) as
subplots within the same window.
(i) 10:10: Save your plot as a le.
6. Conditional Branching
Note the importance of end at the end of
the if-then-else-end construct.
(a) Write a code to check if a given num-
ber n is less than or equal to 10, if
yes, display its square.(for n = 4, 13
and 10)
(b) Write a code to check if a number
is less than 10, if yes, then display
> 10, if it is greater than 10, then
display > 10, else display the num-
ber. (for n = 4, 13 and 10)
7. Iteration
(a) Write a for loop to display all the even
numbers between 1 to 50
(b) Find summation of vector x = [1 2 6
4 2], using iterative procedure. Hint:
Check length(), add each number us-
ing for loop.
(c) Write a code using while loop to dis-
play odd numbers in the range 1 to
25.
8. Polynomials
(a) Construct a polynomial with 3 re-
peated roots at 4 and 2 repeated roots
at 0. Check the roots of the derivative
of this polynomial. (Use derivat)
(b) Write a function that takes a polyno-
mial and gives out only real roots as
output.
(hint isreal )
(c) Write a function that takes a polyno-
mial and gives the INVERSE polyno-
mial, i.e. all roots are inverses of each
other.
(Hint: Coecients are to just be re-
versed.)
(Check that no root was at zero: check
this within the function, and display
error, and exit.)
(d) Write a function that takes a poly-
nomial and gives all the max-
ima/minima candidates.
(Hint: nd all real roots of the deriva-
tive).
9. Ordinary Dierential Equations
Solve the follwoing dierential equations
using Scilab and plot the dependent vari-
able vs independent variable
(a) dy/dx + y/x = x
3
; (x > 0)
(b) cos(x)dy/dx + sin(x)y = x
2
; y(0) = 4
(c) dy/dx = (x
3
y)/x; (y(1) = 0)
(d) dy/dx + y = 2x + 5; (y(1) = 1)
(e) dy/dx + y = x
4
; (y(0) = 0)
(f) dy/dt + (t 1)y = 0; (y(4) = 5)
(g) dy/dt + 2ty = t; (y(2) = 4)
(h) dy/dx + 2xy = 10xe
x
2
; (y(0) = 1)
(i) 2x
2
dy/dx yx = 3; (y(1) = 0)

You might also like