Sie sind auf Seite 1von 4

11MCEC15

Assignment 4

Pillai Dhanya

Do as directed using Scilab : [A] Represent the following linear system as a matrix equation. Solve the system using the inverse method : x + y + 2z w = 3 2x + 5y z -9w = -3 2x + y z + 3w = -11 x 3y + 2z + 7w = -5 Ans.The above set of equations can be written in the Ax = b form. The solution is then given as inverse of A times b Create a Matrix A representing the left hand side of the equations. A=[ 1 1 2 -1; 2 5 -1 -9; 2 1 -1 3; 1 -3 2 7] A = 1. 1. 2. - 1. 2. 5. - 1. - 9. 2. 1. - 1. 3. 1. - 3. 2. 7. Create matrix B representing the right hand side of the equations. B=[3;-3;-11;-5] B = 3. - 3. - 11. - 5. The solution, x, can be obtained using X = inv(A)*B X = - 5. 2. 3. 0. So, x = -5, y = 2, z = 3, w=0

[B] Solve the following examples on the Scilab console : Create a scilab script file to display time on console window. Ans. realtimeinit(1); realtime(3); t1=now(); v1=datevec(t1); Time=v1(4:6) Execute the file to get following output. Time = 11. 2. 51.000001 [ C ] Create a function file to calculate the rowwise and columnwise mean and standard deviation of a user defined matrix. Display the matrix, its mean and standard deviation in output ( hint : use mean() and stdev()) Ans. Mean=mean(x) MeanRow=mean(x,'r') MeanCol=mean(x,'c') Std=stdev(x) StdRow=stdev(x,'r') StdCol=stdev(x,'c')

11MCEC15
endfunction

Pillai Dhanya

Load this function in Scilab using the Execute menu option. The function gets loaded in the scilab environment. Call the function like any other built-in function. [Mean, MeanRow, MeanCol, Std, StdRow, StdCol] = MatrixOp(A) StdCol = 4.9328829 0.0550757 StdRow = 4.2426407 3.6062446 Std = 3.4535417 MeanCol = 4.3333333 7.0366667 MeanRow = 4. 4.55 8.505 Mean = 5.685

2.1142493

[ D ] 01:12: Create a linearly spaced vector from 0 to 1 with 10 points. 01:35: plot sin(x) and cos(x) versus x. Ans. To create a vector with linearly spaced values ranging from 0 to 1, the linspace function is used. linspace(0,1,10) [v]=linspace(0,1,10) v = 0. 0.1111111 0.2222222

0.3333333

0.4444444

0.5555556

0.6666667

0.7777778

0.8888889

1.

To plot cod(x) versus x, where x is a vector, plot command can be used. plot command can be used to plot set of 2-D curves. -->plot(v,cos(v)) -->xlabel('v'); -->ylabel('cos(v)'); -->title('v Vscos(v)');

To plot sin(x) versus x, plot command can be used. plot command can be used to plot set of 2-D curves. -->plot2d(v,sin(v)); -->xlabel('v'); -->ylabel('sin(v)'); -->title('v Vs sin(v)');

11MCEC15

Pillai Dhanya

[E]Solve the following differential equation and plot the dependent variable versus independent variable :dy/dx + y/x = - x3; (x>0) Ans.The usage is [y] = ode(y0,x0,x,f) Where y0 is the initial value of the dependent variable, x0 is the initial value of the independent variable, x is a vector constituting values at which solution is to be computed, f is the Scilab function that specifies the right hand side of the differential equation. In SCILAB in order to solve differential equations we need to rearrange the differential in the format dy/dx = f(x,y) or dy/dt = f(t,y) The function f(x,y) of rearranged equation is written in SCILAB function file. This function file returns the value of differential at desired integration points. Here: dy/dx + y/x= -x3; when x>0 To solve this differential equation we need rearrange the differential equation dy/dx = -y/x - x3; Now, Create a SCILAB function which specifies the right hand side of this differential equation. functionydot = f(x,y) ydot = - y/x x^3; endfunction The input parameters are y0 = 0;x0 = 0.1; x = 0.1:0.2:10; y = ode(y0,x0,x,f); clf(); plot2d(x,y); xlabel('x'); ylabel('y'); title('xvsy');

11MCEC15

Pillai Dhanya

[F] Read any image previously stored at specified location display/show it. -->im =imread("E:\Linux\Scilab_Workshop\SIVPEx\images\mine.png"); -->imshow(im); This set of commands will load mine.png in im and display the same image in new window.

Das könnte Ihnen auch gefallen