help on 10 linear function

Back to General discussions forum

Rafael E     2015-04-05 19:28:46

If my understand of the problem is correct, given this formula: y = ax + b, we are passing in 2 ordered pairs: x1 y1 x2 y2. Then we are returning a & b.

The first half of my answers are correct, getting a is just finding the slope: all you've got to do is divide difference of the two y-coordinates by the difference of the two x-coordinates.

But I'm not sure what I'm doing wrong when I'm trying to find b. What I think I can do is: using the slope formula: y = ax + b,

  • plug in a,
  • then plug in some (x,y) coordinates. I've tried:
    • one pair (x1, y1),
    • then another pair (x2, y2).
    • The difference of the two pairs: (x1 - x2, y1 - y2),
    • then the difference going the other way: (x2 - x1, y2 - y1).
    • Even the average of the two.

This brute force approach is not working and I'm stuck on this.

What would your approach to finding b in this problem be?

Matthew Cole     2015-04-06 00:32:47

Your first approach (find a - the slope, then b - the intercept using (x1, y1)) should have worked. There's no need for brute force, only algebra.

Make sure you're returning integer values for a and b only. Without seeing your code it's hard to tell what's going wrong otherwise.

Rafael E     2015-04-06 18:11:27

I found the bug in my program. Your suggestion to work through an entire problem in Algebra was a good one!

Turns out I was dividing y by (m*x) to get b. But I should have been subtracting (m*x) from y. Little things like that can be easy to miss when you're processing dozens of lines from an outside file, formatting & the like.

Thanks for your time.

CruiseDevice     2015-07-19 10:05:15

I solved the problem on book. But i'am unable to write code for point-slope formula.

Ratzenfutz     2015-07-19 11:01:49
User avatar

@CruiseDevice:

What code / language do you mean? How to determine a and b, or m and n respectively?

Edit: To avoid spoilers on this forum you might give me a PM, and I'll try to help.

CruiseDevice     2015-07-19 17:56:04

I'am using c++.For solving the Linear function problems there are formulas, which are used to find the values of a and b.There is another formula called point-slope formula, i'am unable to think the logic for implementing that formula. For reference i'am posting this link where an example is shown on how to solve problems related with Linear Function.

http://www.algebra.com/algebra/homework/Linear-equations/Linear-equations.faq.question.530233.html

using m = (y2-y1)/(x2-x1), we get the value of m.

using y-y1 = m(x-x1),we will get the equation for x or y.

Using this newly obtained equation,we can find the value of c.

PS:In this problem the equation given is y(x) = ax+b . Iam using y = mx + c.

Ratzenfutz     2015-07-19 20:19:01
User avatar

I'm quite confused about that point-slope thingy. I usually do

// y = mx + n
// m -> slope; n -> vertical shift
if (x2 != x1)
{
    m = (y2 - y1) / (x2 - x1);
    n = y1 - m*x1;
}

Right now I don't see a point in y - y1 = m * (x - x1). What's that x and y? Where and how will I obtain them?

Please login and solve 5 problems to be able to post at forum