Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Question for SunnyCoder

Posted on 2004-04-24
7
238 Views
Last Modified: 2010-08-05
Hey man. I wanted to write a program to process simple algebra problems..

like:

3x + 15 = 11 - x
4x = -4
x = -1


how would you suggest going about this? I dont plan to write it in C, I was acctually going to write it in Visual Basic, but you are good with math, so I was curious how you would suggest doing it. So far I've created a type structure array to store all the monomials, but how do you suggest processing it, I'm stumpted. If you want to throw out some C code, I can port it to VB.


-Brian
0
Comment
Question by:BrianGEFF719
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 10910362
Will the problems be single variable linear equations like your example?
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10910474
Can we lowly creatures also participate in this question or you want only sunny's suggestion???
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 10914018
Everyone feel free to comment.


Right now I am going to focus on Single Variables.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 84

Expert Comment

by:ozo
ID: 10914618
If your problems will all be single variable linear equations you could just change = to -
evaluate at two x values, then extrapolate to where the expression equals 0
0
 
LVL 84

Expert Comment

by:ozo
ID: 10914637
e.g.
(3x + 15) - (11 - x)
(3*0 + 15) - (11 - 0) = 4
(3*1 + 15) - (11 - 1) = 8
x = 4/(4-8) = -1
0
 
LVL 10

Expert Comment

by:Mercantilum
ID: 10915044
To make it simple (e.g. without going to RPN resolution etc...) you have to get 4 variables
v1 is the number of x on left side
v2 is the number on left side (no x)
v3 is the number of x on right side
v4 is the number on right side (no x)

    e.g.  for 3x + 15 = 11 - x

    v1 = 3
    v2 = 15
    v3 = -1
    v4 = 11

The you calculate
     vx = v1 - v3
     vn = v4 - v2

And you have your result R = vn / vx

   vx = v1 - v3 = 4
   vn = -4
   R = 4 / -4 = -1

How to proceed programmatically (automat)
1 -   initialize all v1,v2,v3,v4 to 0.
2 -   parse the equation left side for v1, v2
3 -   set default sign is "+"
4 -   you get a sign : set sign to + or -
5 -   you get a number : put the number in N
6 -   number is followed by x : do v1 = v1 + N
7 -   number is not followed by x : do v2 = v2 + N
8 -   repeat from 3 etc...

Do the same right side, the vars being v3,v4
Once you get all v1...v4, calculate R as above.
0
 
LVL 10

Accepted Solution

by:
Mercantilum earned 500 total points
ID: 10915054
of course of steps 5 and 6, N is signed by 'sign' (ie  N = N * sign ), sign being 1 if "+", -1 if "-"
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question