You are on page 1of 4

PRACTICAL 10:

Negative binomial
Q. Write a scilab code for x=[0,1,2,3,4,5] and obsfre=[12,50,100,80,45,5] using Negative
Binomial distribution.

function [expfre]=negative(x, obsfre)


n=length(x)-1;
N=sum(obsfre);
xbar=sum(x*obsfre')/N;
r2=sum(obsfre*(x^2)')/N;
var=r2-xbar^2;

p=xbar/var;
q=1-p;

r=round(p*xbar/q);
prob(1)=p^r;

for i=1:n
prob(i+1)=((i-1+r)/i)*q*prob(i);
end;
expfre=round(prob*N);
printf('expected frequencies\n');
printf('------------------------------\n');
disp(expfre);
endfunction
Practical 4:
AIM: Program for solving linear system of equations using Gauss Jordan method.
Scilab Code:-
clc
n= input("enter number of equations ")
A=x_matrix('enter coefficient and constants',zeros(n,n+1))
if det(A(:,1:n))== 0 then disp("It cannot be solved.")
else
for i=1:n
for j=1:n
if j==i then continue
else A(j,:)=A(j,:)- (A(j,i)/A(i,i))*A(i,:)
end
end
end
end
disp(A)
for i=1:n
disp(A(i,n+1)/A(i,i))
end

AIM: Program for solving linear system of equations using Gauss Seidel method.
Scilab Code:-
clc
funcprot(0)
for i=1:3
printf("Enter coefficient of x in%d equation",i)
a(i)=input("")
printf("Enter coefficient of y in%d equation",i)
b(i)=input("")
printf("Enter coefficient of z in%d equation",i)
c(i)=input("")
printf("Enter value of d in %d equation",i)
d(i)=input("")
end
k=input("no of iterations")
x=0
y=0
z=0
for i=1:k
x= (1/a(1))*(d(1)-b(1)*y-c(1)*z)
y= (1/b(2))*(d(2)-a(2)*x-c(2)*z)
z= (1/c(3))*(d(3)-a(3)*x-b(3)*y)
end
printf("value of x is %f \n",x)
printf("value of y is %f \n",y)
printf("value of z is %f \n",z)

PRACTICAL 7:
AIM: Program to evaluate e^x using infinite series.
Scilab Code:-
clc
clear
function y=f(x)
y=exp(x)
endfunction
sum=1
test=0
i=0
term=1
x=input(“Input value of x:”)
while sum~=test
disp(sum,”sum:”,term,”term:”,i,”i:”)
disp(“--------------------------------------”)
i=i+1
term=term*x/i
test=sum
sum=sum+term
end
disp(f(x),”Exact Value”)

Aim:- Numerical Differentiation


A. Programming to obtain derivatives numerically.
Scilab Code:-
clc
clear
x=[1.0 1.2 1.4 1.6 1.8 2.0 2.2];
y=[2.7183 3.3201 4.0552 4.9530 6.0496 7.3891 9.0250];
c=1;
for i=1:6
d1(c)=y(i+1)-y(i);
c=c+1;
end
c=1;
for i=1:5
d2©=d1(i+1)-d1(i);
c=c+1;
end
c=1;
for i=1:4
d3(c)=d2(i+1)-d2(i);
c=c+1;
end
for i=1:3
d4(c)=d3(i+1)-d3(i);
c=c+1;
end
c=1
for i=1:2
d5(c)=d4(i+1)-d4(i);
c=c+1;
end
c=1
for i=1:1
d6(c)=d5(i+1)-d5(i);
c=c+1;
end
x0=1.2
h=0.2;
f1=((d1(2)-d2(2)/2+d3(2)/3-d4(2)/4+d5(2)/5/h);
printf(„the first derivation of function at 1.2 is:%f\n‟,f1);
f2=(d2(2)-d3(2)+(11*d4(2))/12-(5*d5(2))/6)/h^2;
printf(„the second derivation of function at 1.2 is:%f\n‟,f2);

You might also like