Prac 5 Code
Prac 5 Code
2.
v1 =
15. 32. 44.
1.
v2 =
13. 26. 39. 45.
1.
v3 =
12. 24. 48. 34. 35.
1.
-----------------------------------------------------------------------------------
---------------------------------
program4: Create a function for use of Euclidean algorithm
code :
function [ans]=myf(a,b) //myf is name of your function
q=fix(a/b); //quotient
rem=modulo(a,b); // reminder
k=q*b+rem; // division formula
ans=b
if(rem~=0)then // check value of rem is not equal to 0
myf(b,rem) //call function again and replace of values a by b and b by rem
end
endfunction
ans=myf(330,156)
disp(ans,'GCD of given numbers')
-----------------------------------------------------------------------------------
-----------------------------------
output :
6
GCD of given numbers
-----------------------------------------------------------------------------------
---------------------------------
program5: Write a program for roots of equation using poly and root function
code:
disp('factor of equations')
t=poly([2,3],'t') //we are passing factor then equation formed
a=factors(t) // we will get factors of the eqn
disp(a)
t=poly(0,'t')
f=t^2-3*t+2
r=int32(roots(f))// roots of equation t^2-3t+2
disp(r)// roots are 1 and 2
-----------------------------------------------------------------------------------
----------
output :
"factor of equations"
t =
6 -5t +t²
a =
a(1)
-3 +t
a(2)
-2 +t
r =
2
1