Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Algorithms and Computation in Engineering

HOMEWORK #1 (section1)
Aim
The aim is to write tasks given in the specified time period in the scilab program. Present our tasks in
the form of an engineering report.

Introduction
Three tasks were given in this assignment. The first task is to assign vector elements to variables.The
second task is to create a row Matrix. The third task is create a function chart.

TASK 1

You are given, an A vector. A= [0.3 2 -1 4 0 -5 0.1 8 -3.4 7 -2.3 0 -2.8]


clc; //Clear console
clear; //Clear functions & variables
A=[0.3 2 -1 4 0 -5 0.1 8 -3.4 7 -2.3 0 -2.8]; //write a vector
b = A<0; //numbers less than zero
neg = A(b) //assign the count to a variable called b.
disp(neg) //disp negative

c= A> 0; //number of positive elements in A vector


pos= A(c) //assign the countto a variable called c.
disp(pos) //display positive numbers

d = A ; //the number of zeros and others in A vector


disp(d), //disp
TASK 2.

This time, create a random row matrix of 1x15 having integer values between -10 and 10, and assign
to A vector.
clc;//clear console
clear; //clear functions & variables
A=grand(1,15,"uin", -10,10);//create a random row matrix of 1x15 having integer values between -10 and 10
disp(A)

b = A < 0;// negative elements in A vector


neg = A(b)//Add negative elements in A vector to matrix b
disp(neg);//disp neg numbers

c= A > 0;// positive elements in A vector


pos = A(c)//Add positive elements in A vector to matrix c
disp(pos)//disp pos numbers

d= A==0 ;//zero elements in A vector


zero = A(d)//Add zero elements in A vector to matrix d
disp(zero)//disp
Task3.
For the following function plot 𝑥𝑥(𝑡𝑡), 𝑥𝑥(𝑡𝑡 − 2), 𝑎𝑎𝑎𝑎𝑎𝑎 𝑥𝑥(𝑡𝑡 + 2) in one figure with different colors
(assume −10 ≤ 𝑡 ≤ 10 )
clc;//clear console
clear; //clear functions & variables
t= [-10:10] //assume −10 ≤ 𝑡𝑡 ≤ 10

y1 = exp(-abs(t));
y2 = exp(-abs(t-2));
y3 = exp(-abs(t+2));

plot(t,y1,'b') //plot y1 in blue


plot(t,y2,'r') //plot y2 in red
plot(t,y3,'g')// plot y3 in green

Conclusion
Software simplifies dealing with vectors. Built-in functions and constant. Similarly, plot
routines allow a quick depiction of the functions. We assigned a random row matrix to a vector.
References
George B. Thomas, M. D. (2005). Thomas' Calculus Early Transcendentals (11th Edition). Boston, MA
United States: Addison-Wesley Longman Publishing Co., Inc. Yeralan, S. (2016). An Introduction to
Industrial Engineering through Computation, First Edition.

You might also like