How to do CHINESE REMAINDER THEOREM (CRT) USING MATLAB CODE
1.Introduction:-
2.Problem Statement:-
To generate X using the chinese remainder theorem.
3.Program:-
clc;
clear all;
close all;
a1=input('Enter value of a1:');
m1=input('Enter value of m1:');
a2=input('Enter value of a2:');
m2=input('Enter value of m2:');
a3=input('Enter value of a3:');
m3=input('Enter value of m3:');
M=m1*m2*m3
M1=M/m1
M2=M/m2
M3=M/m3
M11=mod(M1,m1)
M12=mod(M2,m2)
M13=mod(M3,m3)
x=mod(((a1*M1*M11)+(a2*M2*M12)+(a3*M3*M13)),M);
display (x);
4.How to use this code:-
Here you have to only copy the code to MATLAB and just run it after that you have to give values of a1, a2, a3, m1, m2, m3.
5.Output :-
6.Conclusion -
Here we have successfully generate X for chinese remainder theorem using the MATLAB.
CRT states that below equation having unique solution if moduli are relative prime.
x=a1 mod m1
x=a2 mod m2
.
.
.
x=a(n) mod m(n)
x=a1 mod m1
x=a2 mod m2
.
.
.
x=a(n) mod m(n)
2.Problem Statement:-
To generate X using the chinese remainder theorem.
3.Program:-
clc;
clear all;
close all;
a1=input('Enter value of a1:');
m1=input('Enter value of m1:');
a2=input('Enter value of a2:');
m2=input('Enter value of m2:');
a3=input('Enter value of a3:');
m3=input('Enter value of m3:');
M=m1*m2*m3
M1=M/m1
M2=M/m2
M3=M/m3
M11=mod(M1,m1)
M12=mod(M2,m2)
M13=mod(M3,m3)
x=mod(((a1*M1*M11)+(a2*M2*M12)+(a3*M3*M13)),M);
display (x);
4.How to use this code:-
Here you have to only copy the code to MATLAB and just run it after that you have to give values of a1, a2, a3, m1, m2, m3.
5.Output :-
Command Window
6.Conclusion -
Here we have successfully generate X for chinese remainder theorem using the MATLAB.
Comments
Post a Comment