Professional Documents
Culture Documents
WK 3
WK 3
WK 3
Pseudocode
Clear console
Clear functions & variables
Define function f(𝑥) = (𝑥2+2𝑥)e-𝑥
Define function g(𝑥) = 𝑠𝑖𝑛(𝑥/2)
Assign x the interval −2≤𝑥≤5 with 50 points
Clear figure
Plot f(𝑥) & g(𝑥)
Scilab code
clc; //Clear console
clear; //Clear functions & variables
//Define function f(𝑥) = (𝑥2+2𝑥)e-𝑥
function y=f(x);
y=(x^2+2*x)*exp(-x);
endfunction
//Define function g(𝑥) = 𝑠𝑖𝑛(𝑥/2)
function y=g(x);
y=sin(x/2);
endfunction
//Assign x the interval −2≤𝑥≤5 with 50 points
x=linspace(-2,5,50)
clf; //Clear figure
//Plot f(𝑥) & g(𝑥)
plot(x,f,"r",x,g,"g")
Plot of sequence of points using for command. u(n)=(-0.8)n
Pseudocode
Clear console
Clear functions & variables
For n from 1 to 50
u(n) takes the value (-0.8)n
End for
Plot n and u(n)
Scilab code
clc; //Clear console
clear; //Clear functions & variables
//For n from 1 to 50
//u(n) takes the value (-0.8)^n
//End for
for n=1:50
u(n)=(-0.8)^n
end
//Plot u(n)
plot(u,"*r")
Determine the future value of a deposit both simple interest and
compound interest defining function in the SCILAB program. Plot a
graph with properly labelled legends and axis (x-y) between the future
values by simple and compound interest versus the time if the USD
100,000 is deposited in the bank with an interest rate of 9%.
Pseudocode
Clear console
Clear functions & variables
Define function to calculate interest and principal sum
where si=p+p*r*t/100
and ci=p*(1+r/100)t
Assign p the principal sum 100000$
Assign r the interest rate 9%
Assign t time 1 to 10
Calculate interest rates and assign them to y
Plot time versus y
Put legends, title and labels
Scilab code
clc; //Clear console
clear; //Clear functions & variables
//Define function to calculate interest and principal sum
//where si=p+p*r*t/100
//and ci=p*(1+r/100)^t
function y=interest(p, r, t)
si=p+p*r*t./100
ci=p.*(1+r/100)^t
y=[si ci]
endfunction
p=100000; //Assign p the principal sum 100000$
r=9; //Assign r the interest rate 9%
t=[1:10]'; //Assign t time 1 to 10
//Calculate interest rates and assign them to y
y=interest(p,r,t)
//Plot time versus y
plot(t,y)
//Put legends, title and labels
xlabel('time in years')
ylabel('Amount, USD of SI,CI')
legend('SI','CI')
xtitle('Comparison of SI and CI for $100000')
xgrid(5,1)