Why is 3-1*8+2*3 equal to 1 [closed] - math

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I used PEMDAS on 3 - 1 * 8 + 2 * 3.
Steps:
1) 1 * 8 = 8
2) 2 * 3 = 6
3) 8 + 6 = 14
4) 3 - 14 = -11
Multiply all the terms, then add and finally subtract but I get -11 as the result.
But when I googled it, it said 1. Where did I go wrong?

By Following the BODMAS rule -
3 - 1 * 8 + 2 * 3
So According to BODMAS Rule-
B → Brackets first (parentheses)
O → Of (orders i.e. Powers and Square Roots, Cube Roots, etc.)
DM → Division and Multiplication (start from left to right)
AS → Addition and Subtraction (start from left to right)
So our equation ->
3 - (1 * 8) + (2 * 3)
3-8+6
-5+6
1

After multiply all the terms,please follow the order of operations.Right steps:
Steps: 1) 1 * 8 = 8 2) 2 * 3 = 6 3)3-8=-5 4)-5+6=1

The order of operations is, as you said it PEMDAS (or BEDMAS whatever you like), but it is also left-to-right. And on top of that: multiplication and division are treated as the same order and so are addition and subtraction.
So your first two steps were right.
3 - (1 * 8) + (2 * 3)
3 - 8 + 6
Now here is where the left-to-right ordering takes place.
((3 - 8) + 6)
(-5 + 6)
1
To make it easier, you can remember that x - y is really just x + (-y). Then the order of subtraction and addition doesn't matter at all.

You are not following the order of operations correctly. You are correct in doing the multiplication first. However, you also must always go from left to right when performing operations of the same type (addition and subtraction or multiplication and division). By using parenthesis, we can make this clearer.
3 - (1*8) + (2*3) => 3 - 8 + 6 => -5 + 6 => 1

Your mistake is in step 3. The - gets applied to 8 so step 3 is: -8 + 6 = -2

Related

Explanation of 1 mod 3

So i've been looking into modulo recently. I'm trying to improve my math skills, which are not the best if i'm honest. But something i am trying to improve. I understand how this works i think. I am also quite competent with long division. However something is bugging me and i can't seem to find an answer for it online.
I know that 7 % 5 = 2 (5 goes into 7 once, with a remainder of 2).
What i don't understand is this;
1 % 3 = 1
How can this be, 3 goes into 1, 0 times, with a remainder of 3? Surely the answer to 1 % 3 = 3?
Can anyone explain this in its most simplest terms please?
Am i correct in thinking that if the dividend (1) is less than the devisor (3) which we know will equal 0 remainder x, it just uses the dividend as the result?
Thanks for your help.
The remainder in 1%3 refers to what remains of 1 (not 3) after you divide by 3. As you have already said, 3 goes into 1 zero times. So -- when you remove 0 multiples of 3 from 1, all of 1 remains. Thus 1 % 3 = 1.
The result of a modulo operation n % m is just that number r for which q * m + r = n (q may be anything). The only requirement we have is that 0 <= r < m.
So for instance:
7 % 5 --> 1 * 5 + 2 == 7 --> r = 2
1 % 3 --> 0 * 3 + 1 == 1 --> r = 1

using CLISP to make equations given a sequence of numbers

so i have to use clisp to create 2 equaline equations given a sequence of numbers
IE user enters 2 2 2 2:
2 + 2 = 2 + 2 ; would be valid
2 - 2 = 2 - 2 ; would also be valid
2 = 2 + 2 - 2 ; valid
2 + 2 + 2 = 2 ; not valid
user enters 6 2 2 2:
6 = 2 + 2 + 2 ; valid
6 = 2 * 2 + 2 ; valid
6 + 2 = 2 * 2 ; not valid
The operates of *, /, +, and - are to be used for basic math, and = to signify that Left Hand Side = Right Hand Side.
My problem lies in my lack of any real lisp training and where to start. I think I would have to use macros, but I'm not sure how to use macros or how macros would be used for this.
I know that initially I would have to define a function such as
(defun findequation (a b c d))
But from there I'm lost
First step: create all combinations of the relevant symbols, with the restriction that exactly one = should be present.
Example input: (2 2 2 2), (+ - * / =)
Example output: (2 + 2 + 2 = 2), (2 + 2 - 2 = 2), (2 - 2 - 2 = 2), …
Second step: use the shunting-yard algorithm to transform the infix list of alternating numbers and symbols into a tree.
Example input: (2 + 2 = 2 - 2)
Example output: (= (+ 2 2) (- 2 2))
Then you can evaluate that to see if it is true.

infix prefix postfix [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I came across this in some brain teaser question bank.
What should be the answer of this?
( (3+1) / 3) * 6
I thought it is 7 but the correct answer is 8.
That can happen only when it is (3+1) * (6/3). Since there are parenthesis given in the expression how can I get 8? I tried to double check and the answer is correct.
Can somebody help me in understanding this?
Working with integers:
((3 + 1) / 3) * 6
= (4 / 3) * 6
= 1 * 6
= 6
Working with floats:
((3 + 1) / 3) * 6
= (4 / 3) * 6
= (4 / 3) * (6 / 1)
As a fraction:
= (6 * 4) / (3 * 1)
= 24 / 3
= 8
This is just simple arithmetic - nothing to do with programming, nor the difference between infix, prefix and postfix notations:
((3+1) / 3) * 6 = (4 / 3) * 6
= 1.333... * 6
= 8
This brain teaser question bank is clearly expecting you to use the usual rules of mathematics - it's not a C brain teaser question bank after all. Even if you were using integer division instead (where 4 / 3 would give 1), the answer would be 6.
See the result on Wolfram Alpha.
By the sound of it, this is basic arithmetic and has nothing whatsoever to do with programming:
(3 + 1) / 3 * 6 =
4 / 3 * 6 =
(4 * 6) / 3 =
24 / 3 =
8

Little help with null space of a matrix

This requires a little knowledge about Matlab and I have none. I was just wondering if someone could point me in the right direction and give me some pointer :)
I have to write a matlab code for finding the Null spaces of matices
A and B, where B = A^T x A. And then nd the general solutions to AX = b1
and BX = b2, where b1= the column [1 2 3 4 5] and b2= the column [ 1 2 3 4 5 6 7 8].
My concern is that I dont really know how to go about this code.
This is what I have so far and I do not think i am in the right track. I have a specific matrix as below.
The rows are divided by semi-colon.
A = [ 1 2 3 4 5 6 7 8;
1 2^2 3^2 4^2 5^2 6^2 7^2 8^2;
1 2^3 3^3 4^3 5^3 6^3 7^3 8^3;
1 2^4 3^4 4^4 5^4 6^4 7^4 8^4;
6 8 1 1 7 9 0 7 ]
B = A’A (this is how transpose is written)
C = null(A)
D = null(B)
I feel like there should be a rref somewhere - I'm just not getting anywhere. Please point me in the right direction.
Ok so I updated it to the this now....My username changed from jona and I dont know why
A = [ 1 2 3 4 5 6 7 8;
1 2^2 3^2 4^2 5^2 6^2 7^2 8^2;
1 2^3 3^3 4^3 5^3 6^3 7^3 8^3;
1 2^4 3^4 4^4 5^4 6^4 7^4 8^4;
6 8 1 1 7 9 0 7 ]
B = A’*A (this is how transpose is written)
null(A)
null(B)
b1=[1; 2; 3; 4; 5 ];
b2=[1; 2; 3; 4; 5; 6; 7; 8 ];
end
rref(A,b1)
rref(B,b2)
end
However I still don't feel this is right :(
#Chris A. I know the null space is the solution to Ax=0. However I'm confused on how to use it to find general solution using the b1 and b2 I have. Is it possible for you to explain to me the connection? I don't undertand the book as much.
In MATLAB, arithmetic operations need to be explicit, i.e. a(b+c) should be written as a*(b+c)
Have you tried writing B as
B=A'*A;
Also, you seem to be using a different character for the transpose... You're using ’, the unicode character for single right quotation when you should be using ' or the unicode character for apostrophe.
Ok, so the bottom line is that the null space is the set of all vectors x such that A * x = 0. You got that right. And C is an orthonormal basis for the vectors in the null space. So that means if you have a particular solution (let's call it v) such that A * v = b1 then the space of solutions is the vector v plus any combination of vectors in the null space.
For the case of A, the size (second dimension) of your C will tell you the dimension of the null space. Each one of the vectors in C will be a vector in the null space.
To get v you can do v = A \ b1. You can write arbitrary combinations of vectors in C by C * c where little c is a column vector that is the size of the null space.
The general solution is thus v + C * c where c is any vector that is the dimension of the null space. To see that this solve the system, just plug it back in
A * (v + C * c) =
A * v + A * C * c =
b1 + 0 * c =
b1
Edit: It's the exact same idea for finding the solution to A'*A * x = b2, just anywhere you see A in the above discussion, replace it with A'*A and anywhere you see b1 replace it with b2. The solutions to A * x = b1 and A'*A * x = b2 are separate problems.

Math question: How know section number on a list

Imagine I have this list, that is divided by 3
1
2
3
4
5
6
7
8
9
Now, I have 9 items, grouped in 3 sections.
My question is how know in which section is 6 (ie: 6 belong to section 2, 2 to section 1, 9 to section 3)
Hmmm...... section = ((item-1) / 3) + 1
section = ceiling (n / 3)
For example,
ceiling (4 / 3) = ceiling ( 1.33 ) = 2
For a list of items divided into sections of size n, the section s of an item i is given by:
s = (i + (n-1)) / n,
where the / is integer division.
So, for your example, item 6 gives (6 + (3-1))/3 = (6+2)/3 = 8/3 = 2.
This applies to many other things as well - I encountered it as "How many nodes do I need to request on a cluster with n CPUs per node?"
I'm not totally sure what you're asking, but give this a try:
floor((itemNumber - 1)/numberOfGroups) + 1

Resources