Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Question 1

Option Explicit
Sub Question1()
Const datasheetname = "Sheet1"
Dim xl, xu, xnew, fxl, fxu, fxnew, xold, eo, tol !s Double
Dim i, n !s "nte#e
$s#%ox ("&an $uhammad 'ai( bin & )uso*")
$s#%ox ("+E+1,--./")
xl = "nput%ox("Ente lowe bound")
xu = "nput%ox("Ente uppe bound")
fxl = -01.2 3 xl 3 Exp(41.- 5 xl) 4 -01.2 3 xl 6 .-
fxu = -01.2 3 xu 3 Exp(41.- 5 xu) 4 -01.2 3 xu 6 .-
n = "nput%ox("Ente iteation")
tol = "nput%ox("Ente speci7ed eo")
"f fxl 3 fxu 8 - 9hen
i = 1
xold = ,
Do
xnew = (xl 6 xu) 5 :
fxl = -01.2 3 xl 3 Exp(41.- 5 xl) 4 -01.2 3 xl 6 .-
fxu = -01.2 3 xu 3 Exp(41.- 5 xu) 4 -01.2 3 xu 6 .-
fxnew = -01.2 3 xnew 3 Exp(41.- 5 xnew) 4 -01.2 3 xnew 6 .-
eo = !bs((xnew 4 xold) 5 xnew) 3 1--
"f fxl 3 fxnew 8 - 9hen
xl = xl
xu = xnew
Else"f fxl 3 fxnew ; - 9hen
xl = xnew
xu = xu
Else
Exit Do
End "f
"f eo 8 tol 9hen
Exit Do
Else
xold = xnew
End "f
i = i 6 1
<oop &hile i 8= n
Else
$s#%ox ("$ass cannot be found")
End "f
$s#%ox (""teation = " = i)
$s#%ox ("$ass = " = xnew)
&o>sheets("Sheet1")0?an#e("%1") = xnew
&o>sheets("Sheet1")0?an#e("%:") = i
End Sub
Question :
clc@
clea@
disp (A&an $uhammad 'ai( bin & )uso*A)@
disp (A+E+1,--./A)@
disp (AQuestion :A)@
n = input (ABnEnte si(e of matix nxnBnA)@
C "nput elements
fpintf (ABnA)@
fo i = 1Dn
fo E = 1Dn61
fpintf (A"nput element into a(Cd)(Cd)BtA,i,E)@
a(i,E) = input (A A)@
end
end
C Elimination
fo E = 1Dn41
fo i = E61Dn
fac = a(i,E)5a(E,E)@
fo > = EDn61
a(i,>) = a(i,>) 4 fac3a(E,>)@
end
end
end
C %ac> substitution
fo i = n41D41D1
sum = -@
fo E = i61Dn
if E == n
x(n) = a(n,n61)5a(n,n)@
end
sum = sum 6 a(i,E)3x(E)@
end
x(i) = (a(i,n61)4sum)5a(i,i)@
end
C ?esults
fpintf (ABn!u#mented matix is displaFed belowBnBnA)@
disp (a)@
fpintf (ABnA)@
fo i = 1Dn
fpintf (Ax(Cd) = C0.fBnA,i,x(i))@
end
&an $uhammad 'ai( bin & )uso*
Question :
Ente si(e of matix nxn
2
"nput element into a(1)(1) 1
"nput element into a(1)(:) 1
"nput element into a(1)(,) 1
"nput element into a(1)(2) 1
"nput element into a(1)(.) :
"nput element into a(:)(1) :
"nput element into a(:)(:) ,
"nput element into a(:)(,) 41
"nput element into a(:)(2) :
"nput element into a(:)(.) G
"nput element into a(,)(1) 1
"nput element into a(,)(:) 1
"nput element into a(,)(,) ,
"nput element into a(,)(2) 4:
"nput element into a(,)(.) 41
"nput element into a(2)(1) 1
"nput element into a(2)(:) :
"nput element into a(2)(,) 1
"nput element into a(2)(2) 41
"nput element into a(2)(.) 4:
!u#mented matix is displaFed below
10---- 10---- 10---- 10---- :0----
- 10---- 4,0---- - ,0----
- - :0---- 4,0---- 4H0----
- - - :0.--- .0----
x(1) = 10-----
x(:) = -0-----
x(,) = 410-----
x(2) = :0-----
;;

You might also like