Best way to solve a first degree equation with multiple variables [closed] - algorithm

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 5 years ago.
Improve this question
I would like to solve a first degree equation with multiple variables (not a system of equations) like :
10x + 5y + 7z = 630
Is there any way to solve it without using bruteforce?
Solutions must be integers.

Regroup the first two terms as 10x+5y = 5(2x+y) = 5t.
Then t/7 + z/5 = 18.
As 5 and 7 are relative primes, t = 7k and z = 5(18-k), where k is abritrary.
Finally, y = t - 2x = 7k - 2x, where x is arbitrary.
As we can check,
10 x + 5 (7k - 2x) + 7 5 (18-k) = 630.

No you can't, you have an infinity of solutions in this case.
To solve such problem you shoud have a system with at least the same number of equations as the number of variables.
Another trick, in some cases you could solve it as an underdetermined system.

Related

Correct Syntax for getting the sum of a matrix - Octave [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am taking Andrew Ng's class on Machine Learning and within implementing a Regularized Cost Function for a Neural Network, we have to calculate:
Simply put, ignoring the bias units (the first column), we have to get the sum of all the elements of the matrix squared.
This is the code that I tried writing:
reg_theta1 = Theta1(:,2:end);
reg_theta2 = Theta2(:,2:end);
sum_theta1 = sum(sum(reg_theta1.^2 ,2));
sum_theta2 = sum(sum(reg_theta2.^2 ,2));
J = J + (lambda/2*m)*(sum_theta1 + sum_theta2);
However, I found online a similar answer:
penalty = (lambda/(2*m))*(sum(sum(Theta1(:, 2:end).^2, 2)) + sum(sum(Theta2(:,2:end).^2, 2)));
J = J + penalty;
And that did return the correct result.
The logic is precisely the same, so there must a mistake in my syntax, but I simply can't find it.
What am I doing wrong?
(lambda/2*m) = (lambda/2)*m ≠ (lambda/(2*m))

Gamma distribution [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Let X~gamma(2,1).
Find:
P(X>=2)
(X<=10)
I'm struggling to determine how to solve this. I know you must integrate some function from 2 to infinity and 0 to 10 but don't know what to integrate.
There are actually two ways to define Gamma-distribution - one with scaling 'theta' and another with inverse scale 'beta', see https://en.wikipedia.org/wiki/Gamma_distribution
Fortunately, for parameter value of 1 there is no difference.
So you have to integrate PDF
f(x) = (1/G(2)) * x * exp(-x)
Gamma function at 2 is equal to 1. G(2)=1, so
P(x) = S x exp(-x) dx
where S is integration notation.
P(x) = -(x+1)*exp(-x)
So now you have to substitute limits

What is the fastest way to multiply a number by 2? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am aware that there are multiple ways of multiplying numbers by 2:
v << 1
v * 2
v >> -1
v + v
v - -v
Which is fastest?
I am using Assembly on an intel x86 processor.
There's obviously not one answer here. The answer will depend on the specific processor in use, at least.
Most of the time, your compiler will know, so most of the time, you can just write * 2 in your code, maximizing clarity to your readers and efficiency.
If you really care, you'll have to perform careful measurements yourself.
(Also, multiplying by two is so basic that there might not even be a measurable difference between v * 2, v + v, and v << 1.)

Get the mode of a matrix [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a matrix that is 300x50 big filled with integers. I want to find what number appears the most in that 300x50 matrix and have it returned as an integer.
Just use mode on the linearized matrix:
mode(matrix(:))
Example:
>> matrix = [3 2 3; 2 2 1]
matrix =
3 2 3
2 2 1
>> mode(matrix(:))
ans =
2

an algorithm with some arithmetics [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 want to write a particular function which does some calculation but i have no idea what the algorithm should be:
Requirement
I want to write a function in which you pass in a number and it returns a value from 0 to 1.
if i pass in a 0, it returns a 1 and as you increase the value of the input the output gets closer to 0.
This is similar to a y = 1/x function
but i want to set markers such as if the input is 300, it returns a 0.75 and if it is 600 it returns a 0.5
Is there such a formula which can help me do this?
I have come up with a function which does this!
I used Lagrangian Interpolation but it's not very simple. Instead, another (far more simple) answer that works only until 600;
f(x)=-(x-1200)/1200
If you know range high value, say for example 1200
The output should be 1-(300/1200) = 1 - 0.25 = 0.75
For input x, Formula is 1 - (x/Rangehighvalue)

Resources