Results 1 to 26 of 26

Thread: I need a small help in visual studio regarding to math..

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    I need a small help in visual studio regarding to math..

    Hello, I'm making a program to solve equation with three unknowns, I got the solution of the three simultaneous from here, I don't know how it works.
    So, I faced a problem which is the 3 answers of x,y,z are wrong!!!
    The Simultaneous are:
    ax + by + cz = j
    dx + ey + fz = k
    gx + hy + iz = l

    the code is:
    Dim a, b, c, d, f, g, h, i, e As Integer
    Dim j, k, l As Integer

    Dim x, y, z As Double

    a = Val(txtA.Text)
    b = Val(txtB.Text)
    c = Val(txtC.Text)
    d = Val(txtD.Text)
    e = Val(txtE.Text)
    f = Val(txtF.Text)
    g = Val(txtG.Text)
    h = Val(txtH.Text)
    i = Val(txtI.Text)
    j = Val(txtA.Text)
    k = Val(txtK.Text)
    l = Val(txtL.Text)
    x = (j * e * i + b * f * l + c * k * h - c * e * l - b * k * i - j * f * h)
    y = (a * k * i + j * f * g + c * d * l - c * k * g - j * d * i - a * f * l)
    z = (a * e * l + b * k * g + j * d * h - j * e * g - b * d * l - a * k * h)

    txtX.Text = Convert.ToString(x)
    txtY.Text = Convert.ToString(y)
    txtZ.Text = Convert.ToString(z)

    I would like to get a help from you guys!! Thanks in advance.

  2. #2
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: I need a small help in visual studio regarding to math..

    I would think you would need something called a "Gaussian elimination" (Or in otherwords, some peace of serious math)
    An example of doing just that is given here http://www.vb-helper.com/howto_net_g...imination.html
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    I don't even know what is this and how it works, I don't think it will help me
    ps: the link you provided is for something different

  4. #4
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: I need a small help in visual studio regarding to math..

    You could always copy the code, and try it.

    P.s
    The link i provided should do just that what you asked, solve a set of equations.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  5. #5
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    It looks like the method used is by use of determinants. The calculation for x, y , z are the evaluation of one of the required determinants. However, the results obtained need to be divided by the determinate of the lhs of the equation which is

    Dim t As Integer

    t = a * e * i - a * h * f + d * h * c - d * b * i + g * b * f - g * e * c

    so x = x / t, y = y / t, z = z / t
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    Like this?
    t = a * e * i - a * h * f + d * h * c - d * b * i + g * b * f - g * e * c
    x = (a * e * l + b * k * g + j * d * h - j * e * g - b * d * l - a * k * h) / t
    y = (a * k * i + j * f * g + c * d * l - c * k * g - j * d * i - a * f * l) / t
    z = (j * e * i + b * f * l + c * k * h - c * e * l - b * k * i - j * f * h) / t
    In addition, x and z solutions are right but y still wrong.

  7. #7
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    What is the equation you are trying to solve, what answers are you getting and what are the expected answers.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    the equations:
    1x+1y+1z=9
    2x+1y-2z=-1
    3x+1y-1z=5

    The answers I get: X= 4 Y= -5 Z=2
    The expected answers: X= 2 Y= 3 Z= 4

    Name:  WindowsApplication3.vshost_2017-12-06_16-13-02.png
Views: 217
Size:  14.3 KB
    Last edited by casper.mta; Dec 6th, 2017 at 09:14 AM.

  9. #9
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    From checking the determinate calculations for the equation as defined in post #1, the order of the used letters does not correlate to their usage in the calculations. The required calculations given the letters used in the equation are

    Code:
    t = a * e * i - a * h * f + d * h * c - d * b * i + g * b * f - g * e * c;
    
    x = (j * e * i - j * h * f + k * h * c - k * b * i + l * b * f - l * e * c) / t;
    y = (a * k * i - a * l * f + d * l * c - d * j * i + g * j * f - g * k * c) / t;
    z = (a * e * l - a * h * k + g * b * k - g * e * j + d * h * j - d * b * l) / t;
    From post #8, these give the required answers of x = 2, y = 3, z = 4.

    From where you got the equations in post #1, the letters used don't correlate with the letters used in the equation.
    Last edited by 2kaud; Dec 9th, 2017 at 06:09 AM. Reason: Correction as per post #25
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    First, http://www.vbforums.com/showthread.p...three-unknowns from here i got the solution for the 3 equations.
    Second, I'm sorry for saying this but I tried the codes and the same answers appeared!

  11. #11
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: I need a small help in visual studio regarding to math..

    Quote Originally Posted by casper.mta View Post
    First, http://www.vbforums.com/showthread.p...three-unknowns from here i got the solution for the 3 equations.
    Second, I'm sorry for saying this but I tried the codes and the same answers appeared!
    Have you tried (Downloaded) and looked the example i posted in the link?
    I have, and it returned exactly what you want...
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    I tried to send you a private message, but, I failed. I don't know who the system which you provided works, I don't even know how to use it.

  13. #13
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: I need a small help in visual studio regarding to math..

    Quote Originally Posted by casper.mta View Post
    I tried to send you a private message, but, I failed. I don't know who the system which you provided works, I don't even know how to use it.
    At the bottom of the page, you can download the project.

    When you run the project, replace all the values with the values you want, remembering to put a space between them, then click solve.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  14. #14

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    Oh, that's right bro! but my project is different!! I wanna something like the picture I provided

  15. #15
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    I tried the codes and the same answers appeared
    This is the c++ program I used to test.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
    int a = 1,
    	b = 1,
    	c = 1,
    	d = 2,
    	e = 1,
    	f = -2,
    	g = 3,
    	h = 1,
    	i = -1,
    	j = 9,
    	k = -1,
    	l = 5;
    
    double x, y, z;
    
    int		t = a * e * i - a * h * f + d * h * c - d * b * i + g * b * f - g * e * c;
    
    		x = (j * e * i - j * h * f + k * h * c - k * b * i + l * b * f - l * e * c) / t;
    		y = (a * k * i - a * l * f + d * l * c - d * j * i + g * j * f - g * k * c) / t;
    		z = (a * e * l - a * h * k + g * b * k - g * e * j + d * h * j - d * b * l) /t;
    
    		cout << "t: " << t << " x: " << x << " y: " << y << " z: " << z << endl;
    }
    and displays

    Code:
    t: -4 x: 2 y: 3 z: 4
    which are the required solutions.
    Last edited by 2kaud; Dec 9th, 2017 at 06:10 AM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  16. #16
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: I need a small help in visual studio regarding to math..

    Quote Originally Posted by casper.mta View Post
    Oh, that's right bro! but my project is different!! I wanna something like the picture I provided
    Then you would have to modify the example, till it looks like you want.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  17. #17

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    Which program can I make program like the picture I uploaded with C++? I don't know anything about C++ maybe I'll need your help again :|

  18. #18
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Question Re: I need a small help in visual studio regarding to math..

    Huh?? the example wasn't in c++, it was in vb.net.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  19. #19

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    I will try it out, but I was talking to 2kaud

  20. #20
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    Quote Originally Posted by casper.mta View Post
    Which program can I make program like the picture I uploaded with C++? I don't know anything about C++ maybe I'll need your help again :|
    You asked for help with the maths, not the code. The program as posted in post #15 shows the required equations and the result produced. If you change the equations in the program in post #1 you should obtain the same results. Once you have the correct maths, I would suggest that if you need programming advice you post a new thread on the relevant programming forum.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  21. #21
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    Quote Originally Posted by Goggy View Post
    Huh?? the example wasn't in c++, it was in vb.net.
    Yes, but I'm c++ and used c++ to prove the maths. The equations can be easily moved to the vb program as post #1.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  22. #22
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    Based upon the equations in post 15, this vb program should work - but has not been tried.

    Code:
    Dim a, b, c, d, f, g, h, i, e As Integer
    Dim j, k, l, t As Integer
    
    Dim x, y, z As Double
    
    a = Val(txtA.Text)
    b = Val(txtB.Text)
    c = Val(txtC.Text)
    d = Val(txtD.Text)
    e = Val(txtE.Text)
    f = Val(txtF.Text)
    g = Val(txtG.Text)
    h = Val(txtH.Text)
    i = Val(txtI.Text)
    j = Val(txtJ.Text)
    k = Val(txtK.Text)
    l = Val(txtL.Text)
    
    t = a * e * i - a * h * f + d * h * c - d * b * i + g * b * f - g * e * c
    
    x = (j * e * i - j * h * f + k * h * c - k * b * i + l * b * f - l * e * c) / t
    y = (a * k * i - a * l * f + d * l * c - d * j * i + g * j * f - g * k * c) / t
    z = (a * e * l - a * h * k + g * b * k - g * e * j + d * h * j - d * b * l) / t
    
    txtX.Text = Convert.ToString(x)
    txtY.Text = Convert.ToString(y)
    txtZ.Text = Convert.ToString(z)
    NOTE that in the code in post #1, there is an issue with j
    Code:
    j = Val(txtA.Text)
    should be

    Code:
    j = Val(txtJ.Text)
    Last edited by 2kaud; Dec 9th, 2017 at 06:10 AM.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  23. #23

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    How stupid am I. Thank you very much!!

  24. #24

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    @2kaud, can you try these equations?
    x-y-z=-2
    x+y+z=12
    2x+2y=18

    The answers I get: x= 14, y= 4, z= 3
    The expected answers: x=5, y=4, z=3

  25. #25
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: I need a small help in visual studio regarding to math..

    Yes. So do I. Doh!!!!

    ....

    OK. I see the finger problem. There's been a mistype when entering from my paper.

    Code:
    x = (j * e * i - j * h * f + k * h * c - k * b * i + l * b * f - l * e * 1) / t
    should be
    Code:
    x = (j * e * i - j * h * f + k * h * c - k * b * i + l * b * f - l * e * c) / t
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  26. #26

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: I need a small help in visual studio regarding to math..

    Thank you again, sir!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width