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 件のコメント

Rik
Rik 2019 年 5 月 3 日
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 2019 年 5 月 3 日
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 2019 年 5 月 5 日
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 2019 年 5 月 13 日
(Answers Dev) Restored edit

サインインしてコメントする。

回答 (1 件)

Guillaume
Guillaume 2019 年 5 月 3 日

2 投票

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 件のコメント

Jacob
Jacob 2019 年 5 月 3 日
Thanks but i'm still confused. Where does the 10 come from in the question?
Steven Lord
Steven Lord 2019 年 5 月 3 日
As an example, 23 is 2*10 + 3.
How would you decompose 1234 in a similar way?
Jacob
Jacob 2019 年 5 月 3 日
10*123 + 4. I don't understand how using rem gets what the question is asking for.
Guillaume
Guillaume 2019 年 5 月 3 日
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 2019 年 5 月 3 日
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 2019 年 5 月 3 日
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?
Rik
Rik 2019 年 5 月 3 日
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 2019 年 5 月 4 日
Yeah and I don't know. Do I have to find a way to get the remainder to be ID number?
Rik
Rik 2019 年 5 月 4 日
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 2019 年 5 月 4 日
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?
Walter Roberson
Walter Roberson 2019 年 5 月 4 日
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 2019 年 5 月 4 日
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 2019 年 5 月 4 日
Read the documentation for anonymous functions.
Jacob
Jacob 2019 年 5 月 4 日
How do I restrict the range of a function on a plot?
Rik
Rik 2019 年 5 月 4 日
Read the documentation for fplot.
Walter Roberson
Walter Roberson 2019 年 5 月 4 日
f = @(x) one*x.^2 + two*x + three;
fplot(f, [-5 5])

サインインしてコメントする。

カテゴリ

製品

リリース

R2019a

タグ

質問済み:

2019 年 5 月 3 日

コメント済み:

2019 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by