Help with a basic MATLAB question

Hey, i'm learning how to use MATLAB and I was confused on what was meant by the question. Can someone explain how I can decompose the number using rem please??

4 Kommentare

Rik
Rik am 3 Mai 2019
The task is to turn the number into a vector of its decimal components. So for 864736 you need to find a way to turn that into a vector [8 6 4 7 3 6]. Your teacher wants you to use the rem function to find those values.
You should read the documentation (type doc rem in the command window).
Since the ID has a relatively small length I would propose a different method: turn it into a char array (see sprintf) and then cast it back to a double.
Jacob
Jacob am 3 Mai 2019
Thanks. So I need to work with the one that shows the example
a = 1:5;
b = 3;
r = rem(a,b) ?
How do I apply this to my number?
Rik
Rik am 5 Mai 2019
Please don't delete your question text. It is extremely rude to get free help first and then remove the potential for any future reader to benefit as well.
Rena Berman
Rena Berman am 13 Mai 2019
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guillaume
Guillaume am 3 Mai 2019

2 Stimmen

Given a positive integer, e.g. x = 749623, you're supposed to decompose it into a vector of digits, for my example y = [7, 4, 9, 6, 2, 3].
  • What is the remainder of 749623 / 10 ?
  • What is the remainder of 74962 / 10 ?
  • What is the remainder of 7496 / 10 ?
  • etc.
That should be enough for you to understand what you have to do.

16 Kommentare

Jacob
Jacob am 3 Mai 2019
Thanks but i'm still confused. Where does the 10 come from in the question?
Steven Lord
Steven Lord am 3 Mai 2019
As an example, 23 is 2*10 + 3.
How would you decompose 1234 in a similar way?
Jacob
Jacob am 3 Mai 2019
10*123 + 4. I don't understand how using rem gets what the question is asking for.
Guillaume
Guillaume am 3 Mai 2019
Where does the 10 come from in the question
Your fingers! We've been using the decimal system for a while now...
You do not decompose 1234 into 10*123 + 4. Come on, you've been taught that in primary school or even earlier. Units, Decades, Hundreds, Thousands, etc.
Jacob
Jacob am 3 Mai 2019
1000 + 200 + 30 + 4. I just did what he had done with his example. I don't know how this relates to the rem function though?
Guillaume
Guillaume am 3 Mai 2019
As I asked, given 1234
  • what is the remainder of 1234 / 10
  • what is the remainder of 123 / 10
  • what is the remainder of 12 / 10
and what does the rem function do?
Have you read the documentation for what the rem function does? It calculates the remainder.
%So for two integers a and b
rem(a,b)
%returns a value c such that
a=m*b+c
%where m is an integer m, and c<b
How do you think this relates to the decomposition here?
Jacob
Jacob am 4 Mai 2019
Yeah and I don't know. Do I have to find a way to get the remainder to be ID number?
Rik
Rik am 4 Mai 2019
It is a step by step process:
  • Given 1234, what is the last digit? That has the same answer as finding the remainder for 1234/10.
  • Now we have a variable with the value 4, how can we convert 1234 to 123 to get it ready for the next step? Subtract the remainder and apply the division: (1234-4)/10.
  • Now we have 123, what is the last digit? That has the same answer as .......
  • ....
In the end you have a variable for each digit of your input number (in this case the ID).
Jacob
Jacob am 4 Mai 2019
Thanks but I still don't know how to do this on Matlab. Do I start with an input thing for each of A, B, C etc. and then use the rem function?
six = rem(YourID, 10);
rest = (ID - six)/10;
five = rem(rest, 10);
rest = (last - five)/10;
four = rem(rest, 10);
rest = (last - four)/10;
three = rem(rest, 10);
rest = (last - three)/10;
two = rem(rest, 10);
one = (last - two)/10;
Jacob
Jacob am 4 Mai 2019
Thanks Walter.
How do I let f(x) equal A*x^2 + B*x + C and then sub in f(x1)? I keep getting "undefined function or variable 'x'."
Rik
Rik am 4 Mai 2019
Read the documentation for anonymous functions.
Jacob
Jacob am 4 Mai 2019
How do I restrict the range of a function on a plot?
Rik
Rik am 4 Mai 2019
Read the documentation for fplot.
f = @(x) one*x.^2 + two*x + three;
fplot(f, [-5 5])

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2019a

Gefragt:

am 3 Mai 2019

Kommentiert:

am 13 Mai 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by