Long Division
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi im trying to write a function, that is basically long division, so i will get a value and then also a remainder. Could anybody give me some starting advice please?
function [q,r]=Divide(x,y)
Thats what my first line of my function shall be, where q is the integer value and r the remainder.
Thanks!
2 comentarios
Jan
el 7 de Mzo. de 2012
This is a double post. You got two answers to your former question already: http://www.mathworks.com/matlabcentral/answers/31403-writing-a-function-for-division
Respuestas (2)
Walter Roberson
el 7 de Mzo. de 2012
When you do division by hand, on a piece of paper, what you see is a vector of digits in the numerator and a vector of digits in the denominator. Humans do not usually perceive a number such as 2893 as a single unit: we see it as "two eight nine three". "long division" deals with the situation.
So, if someone gave you pencil and paper and two vectors of digits (numerator and denominator), and asked you to do the division, how would you proceed?
9 comentarios
Walter Roberson
el 7 de Mzo. de 2012
If you post what you have so far, someone might point out problems.
Ben Davis
el 8 de Mzo. de 2012
Editada: Walter Roberson
el 10 de Sept. de 2019
Daniel Shub
el 7 de Mzo. de 2012
In your first comment to Walter, you wrote "and the process is repeated until an answer is obtained." That sounds a lot like a "while" loop to me. Think you could express what you do in terms of a while loop ...
Maybe: While the remainder is less than the denominator DO ...
Then from there think about how to write the do in pseudo code. Finally convert it to MATLAB
0 comentarios
Ver también
Categorías
Más información sobre Parallel Computing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!