Can someone please help me.
i need to write codes in MATLAB.
and i dont know how to proceed.
" Using the multiplicative inverse of 10 mod 23, write code to check whether a number is divisible by 23"
i have an example but it checks if number is divisible by 7.
Please help me.
12 replies to this topic
#1
Posted 16 October 2011 - 08:20 AM
|
|
|
#2
Posted 17 October 2011 - 11:05 AM
Standard response: what do you have so far?
#3
Posted 17 October 2011 - 07:56 PM
clear;
num=input('num');
k=0;
% divisibility rule by 7
% remaining digits- 2(last digit)
while num>0
%for k=1:2,
% express num1 into linear combination of powers of 10
num1=num;
i=0;
rk=[];
num1array=[];
num1arraynew=[];
while num1>0
r=rem(num1,10);
q=floor(num1/10);
i=i+1;
rk(i)=r;
num1=q;
end
ilast=i;
for i=1:ilast,
num1array(ilast-i+1)=rk(i);
end
% array of coefficient of powers of 10
%
num1last=num1array(ilast);
for i=1:ilast-1,
num1arraynew(i)=num1array(i).*10^(ilast-i-1);
end
num1new=sum(num1arraynew)-2*num1last;
k=k+1;
%fprintf('\n k num1array numlast num1new\n');
%fprintf('%d %d %d %d \n',k,num1array,num1last,num1new);
k, num1array, num1last, num1new
num=num1new;
end
k
r3=rem(num1new,7);
if (r3==0)
fprintf(' number is divisible by 7 ');
else
fprintf('\n number is not divisible by 7 \n');
end
I ve this code for divisibilty by 7.
i know i should start by having the multiplicative inverse of 10mod23 and the answer is 7.
now how to modify the code given to make it check for numder divisible by 23, i'm stuck :S
Edited by WingedPanther, 18 October 2011 - 06:41 AM.
add code tags (the # button)
#4
Posted 18 October 2011 - 06:42 AM
In the last few lines, have you tried changing 7 to 23?
#5
Posted 18 October 2011 - 06:50 AM
Dude truely..are you talking about the fprintf lines!!!
#6
Posted 18 October 2011 - 07:15 AM
r3=rem(num1new,7);
Realize, I've NEVER used MATLAB, and the assignment directions look strange, at best. Normally, when I want to check divisibility I just use the modulus operator of whatever language I'm using.
Realize, I've NEVER used MATLAB, and the assignment directions look strange, at best. Normally, when I want to check divisibility I just use the modulus operator of whatever language I'm using.
#7
Posted 18 October 2011 - 07:23 AM
okay.
yeah i tried but it didnt work.
where can i get help for this man??
yeah i tried but it didnt work.
where can i get help for this man??
#8
Posted 18 October 2011 - 01:02 PM
Well, I would start by clearly stating what SHOULD be done. I'd have to do some research to even know what your directions are asking you to do.
#9
Posted 19 October 2011 - 06:36 AM
let me give you the whole thing. and how it is set.
1. Find the multiplicative inverse of 10 mod 23:
2. Hence, write a well-documented Matlabr code to check whether
a number is divisible by 23.
Your code must input
- the number,
and give the outputs:
- whether the number is divisible by 23 or not.
the multiplicative inverse of 10 mod 23 is 7.
i think the code should be edited somewhere.and the answer will be found.
i'm searching also how to solve this problem.
1. Find the multiplicative inverse of 10 mod 23:
2. Hence, write a well-documented Matlabr code to check whether
a number is divisible by 23.
Your code must input
- the number,
and give the outputs:
- whether the number is divisible by 23 or not.
the multiplicative inverse of 10 mod 23 is 7.
i think the code should be edited somewhere.and the answer will be found.
i'm searching also how to solve this problem.
#10
Posted 19 October 2011 - 09:37 AM
My normal understanding, assuming the real number system, is that 10 mod 23 is 10. It's multiplicative inverse is 1/10. How does that help me check whether a number is divisible by 23?
If you're doing Number Theory, then 7 would be the inverse of 10 in Z/Z23.
Stating what SHOULD be done would normally be the algorithm, in pseudocode. Forget MATLAB for a moment. How would you check it by hand?
Looking here: Divisibility rule - Wikipedia, the free encyclopedia it appears that n is divisible by 23 iff n mod 10 + n div 10 * 7 is divisible by 23. If you repeat the process a few times, as needed, it should get you down to one of 23, 46, or 69.
If you're doing Number Theory, then 7 would be the inverse of 10 in Z/Z23.
Stating what SHOULD be done would normally be the algorithm, in pseudocode. Forget MATLAB for a moment. How would you check it by hand?
Looking here: Divisibility rule - Wikipedia, the free encyclopedia it appears that n is divisible by 23 iff n mod 10 + n div 10 * 7 is divisible by 23. If you repeat the process a few times, as needed, it should get you down to one of 23, 46, or 69.
#11
Posted 19 October 2011 - 03:33 PM
Yes i'm doing Number Theory.
By hand!!!
The normal procedure would be adding 7 times the last digit to the rest as stated by Wikipedia.
Here’s one example, to test divisibility by 23. Since 23 x 3 = ( 10 x 7 ) - 1 we know that 10a + b will be divisible by 23 if and only if a + 7b is divisible by 23. Here’s the test with n = 146096 :
14609 + ( 7 x 6 ) = 146351
14635 + ( 7 x 1 ) = 1472
147 + ( 7 x 2 ) = 161
16 + ( 7 x 1 ) = 23
and we have shown divisibility by 23, without any tiresome division.
By hand!!!
The normal procedure would be adding 7 times the last digit to the rest as stated by Wikipedia.
Here’s one example, to test divisibility by 23. Since 23 x 3 = ( 10 x 7 ) - 1 we know that 10a + b will be divisible by 23 if and only if a + 7b is divisible by 23. Here’s the test with n = 146096 :
14609 + ( 7 x 6 ) = 146351
14635 + ( 7 x 1 ) = 1472
147 + ( 7 x 2 ) = 161
16 + ( 7 x 1 ) = 23
and we have shown divisibility by 23, without any tiresome division.
#12
Posted 20 October 2011 - 08:08 AM
So, with that in mind, you need a loop that terminates when your number is less than 70. Then just look to see if your result is one of 23, 46, or 69.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









