C/C++ :: Quadratic Equation Solver - Simplification Function
Jul 6, 2014
So, I successfully made a program that will perform the quadratic equation on three numbers, imaginary or real. however, i am now trying to simplify the result, as to get rid of the "/2a" on the bottom. Hence the simplify() function. I just started to create the simplification function, and am attempting to divide the imaginary part of the solution as well as the real part of the solution by 2a. Somehow, it gives the error, "error:invalid operands of types 'int' and 'double *' to binary 'operator*'" on lines 105 and 106. I suspect it has to do with the pointers and references that i am passing as parameters. Also, just an aside, I have never actually seen "/=" be used. It can be, right? I know "+=" can be.
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>//simplify the answer
using namespace std;
int count=0;
//prototyping
double ans_1(double,double,double);
[Code] ....
View 5 Replies
ADVERTISEMENT
Feb 16, 2015
write codes that could solve a quadratic formula, and my codes are like this:
#include <bjarne/std_lib_facilities.h>
int main()
{
cout << "Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
";
cout << " a? ";
double a;
cin >> a;
cout << " b? ";
[code]....
Which runs perfectly, but I have 2 questions:
1. How to simplify these code? On the assignment sheet the professor wrote about using void solve_linear(double b, double c); and void solve_ quadratic (double a, double b, double c);which I currently dont understand how these works. He asked us to write a well-encapsulated (as short as possible) program.
2. These are for extra points: the precision problem of floating numbers: professor asked us to find a way to get the precise answer of it, like this: Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
a? 1
b? -20000
c? 1.5e-9
Trying to solve the quadratic equation 1*x*x + -20000*x + 1.5e-09 == 0
Using classical formula: Two roots, x = 20000 and x = 0
Using stable formula: Two roots, x = 20000 and x = 7.5e-14
My guess is that
A. Using code like if(x1*x2=a/c) to check if numbers were approximated.
B. Somehow determine the larger one in x1 and x2.
C. Somehow use that larger one to do something
View 2 Replies
View Related
Oct 18, 2013
This is my code:
Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation
[Code] ......
And I keep getting this error:
Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status
View 5 Replies
View Related
Jul 4, 2014
soo quadratic equation solver. output is "x=nan x=nan".
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//prototyping
double ans_1(double,double,double)
[code].....
View 2 Replies
View Related
Feb 3, 2013
I am creating a program that solves the quadratic equation ax^2 + bx +c.
I have this program almost complete except the output of the equation in the function called display_quadratic. I need the program to display the variables a,b,c in the equation ax^2 + bx + c but I am having 2 problems. My first problem is that I cannot get the right addition and subtraction signs for the equation.
For instance, if the program had the values for a,b,c as 2,2,3
it will display 2x^2 2x 3
How can I get it to display 2x^2 + 2x + 3? or if it was negative like 2x^2 - 2x - 3?
My next question is how do I get to not display the coefficients that are 1?
I had an if-else statement but no matter what I created it would overlap with another statement and print out twice. Here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void display_quadratic (float a, float b, float c);
float root1(float a, float b, float c);
[Code] ......
View 2 Replies
View Related
Oct 7, 2013
This is my code for the quadratic equation. It keeps telling me that my else is illegal since no matching if statement and my else statement is missing a statement
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
int main() {
string Name;
[Code] .....
View 3 Replies
View Related
Jan 28, 2014
We are suppose to build a program to do the quadratic formula, which isnt really a issue. my issue is i have a if else loop and my if is being ignored.
what i want it to do is is state that if the (b * /> - 4(a)© is a negative, then it prints out stating it cant do this.
note: i know that i can use the i number system but we have been asked to not too and to do this instead.
here is my code
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, e, f, g, h, i; /* i would love to figure out a way to do this without so many variables*/
[code]....
View 3 Replies
View Related
Oct 22, 2014
I have a task to find errors in this long line of code in order to correctly calculate the solutions of quadratic equations.
Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;
/***********************
* Input / Validation
***********************/
/* Check numbers of arguments, and read input */
validInput = (argc = 4);
[Code] ....
Is a section of the code (the first section). And as you can probably guess, it goes on to calculate for a > 0 etc...
I dont really understand what the validinput section is saying? And a, b and c are never defined so Xcode is just saying a,b,c,root1,root2 are uninitialized and I also dont know what means. Do I need to define these values?
Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;
[Code] ......
View 9 Replies
View Related
Sep 28, 2013
Been trying for a while now to complete a physics degree first year computing task I've been assigned, which is to create a wordsearch solver to read to an array a wordsearch from a .txt file and find words in all directions (x+,x-y+ etc.).
I have a feeling the program is almost complete, but will stop looking for the word once the first character of the word has already come up. For example, if I'm searching for computer, and a c exists in an array element before it, the program will stop searching. I have included my code and the wordsearch file beneath.
Code:
#include <stdio.h>#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h> //Used for the'toupper' functio
int main()
}
[code]....
View 13 Replies
View Related
Dec 17, 2013
I'm working on an anagram solver, and started with words 3 characters big. But it can solve some words and not others.
std::string str = "enp";
std::string match = "";
int chk = 0;
[Code].....
With the string "enp", it knows it matches "pen". But if I use "mum", it doesn't match it with "mum".
Is there something flawed with my algroithm?
View 4 Replies
View Related
Mar 15, 2014
I'm working on a homework problem where we are given a class of functions to traverse a maze and must use those functions to recursively find the end.
The problem I'm having is when the function backtracks it doesn't reset the whole path it came from.
Here is my function that I have created
void solveMaze(Maze M, int path[][MAX])
{
// << overwritten to print the maze out
cout<<M;
[Code].....
View 7 Replies
View Related
Apr 28, 2014
As it is known there are nine boxes and in each box we can put numbers 1-9 without repetition. I am trying to check a given filled Sudoku puzzle whether appropriate numbers are inserted in each of the nine boxes. For the time being I don't consider row repetition and column repetition. I wrote the code using loops and condition
I used 9*9 text-boxes. The names of the textboxes is sequential like for example for the first box
txt11,txt12,txt13
txt14,txt15,txt16
txt17,txt18,txt19
Actually, I used also the controls id to access the text boxes, and each box is checking with the neighboring boxes for equality both in forward -> and backward <-
image
So here is the code
public void BoxCheck() {
int start = 82, end = 74;
int i, b, f;
for (int p = 1; p <= 9; p++, start -= 9, end -= 9) {
richTextBox1.AppendText("Box " + 1);
[Code] ....
This works pretty fine, but is is the right way to do it? it is efficient? Remember for a full checking I have to include row check and column check as well, this is just for checking within each of the 9 boxes in Sudoku.
View 6 Replies
View Related
May 23, 2013
I have given following exercise in my cpp book: Determine the roots of quadratic equations
ax^2 + bx + c = 0
using formula
x = -b +(plus-minus) (root)b^2 - 4ac/2a
i don't now how to write such code...
View 6 Replies
View Related
Sep 17, 2013
I am trying to implement the linear programming solver. This is the header file of the linear programming solver :
/*!
internal
Representation of a LP constraint like:
(c1 * X1) + (c2 * X2) + ... = K
or <= K
or >= K
Where (ci, Xi) are the pairs in "variables" and K the real "constant".
*/
[Code] .....
I want to parse all the constraints and bounds as inputs and get the maximum value of the objective function as the output using the above lpsolver header file. I have also attached the sample file below.
View 14 Replies
View Related
Mar 26, 2014
I'm working on a maze solving program. So far I got the program to solve a maze using the recursive backtracking algorithm. I represent the maze as vector<vector<Square>> where Square is an enum that contains the kind of square (empty, wall, etc.). I use a class Point that contains 2 ints which are used for subscripting the vector of vectors. I have a Point begin and Point end. Now I want the program to solve the maze using the shortest path. I can either use the A* algorithm, Dijkstra's algorithm, or the breadth first search algorithm.
View 6 Replies
View Related
Mar 5, 2013
Code:
/* Sudoku solver using dept-first search*/
#include <iostream>
#include <stack>
using namespace std;
struct valpos//structure which carries information about the position of the cell and its value {
int val;
int row;
int col;
[Code] ....
View 3 Replies
View Related
Feb 25, 2014
I am creating a sudoku solver/generator. I have 81 text boxes on the form. I want the form to automatically clean up the input, eliminating alpha characters, and values under 1 or over 10. Anyways I have this method written, but I really don't want to go through and type up a change method for each text box. Is there to write a method that fires when ANY text box is changed, and gets the string value from the changed text box?
View 5 Replies
View Related
Mar 25, 2013
how to take two variables with values such as a 1; and b 2;. Now you take cout << a + b; and you will get 3, but I want to somehow have a 1; b 2; and c num; then have a + b = c. So what ever I have the user input is for a and be added together will become the value of the c variable.
View 1 Replies
View Related
Oct 30, 2014
I have a small project for school due today but i cant get my head around programming
Ive to create a program where ive to get the values from the user and add them to an equation. I have also to add a selection statement where it will ask for the material being tested which will have its value set in the program.
View 4 Replies
View Related
Apr 14, 2013
Write a program that creates the output shown in the Output Layout section below. The program should create 2 points with x and y coordinates as integers, prompt the user to input the x and y values for one of the points and randomly set the other (-99 to 99 range) and output the length of the radius line segment and the area of the circle that radius defines. The program should then end. Include an SDM for the program and any other appropriate documentation.
Special Calculations:
Distance between 2 points equation:
√((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)
Output Layout: (bold text represents user input)
Please enter the location of your first point.
Enter a value from -99 to 99 for your x coordinate: -2
Enter a value from -99 to 99 for your y coordinate: 17
The location of your second randomly set point.
Your x coordinate: 45
Your y coordinate: -89
The length of the radius line segment from point one to point two is 115.
The area of the circle with a radius of 115 is 41546.33.
Other:
int pAx;
int pAy;
int pBx;
int pBy;
View 3 Replies
View Related
Feb 19, 2015
I'm writing an algorithm on a microcontroller in C.
One of the iterations that takes a long time involves the following equation, summing the product of pairs of variables:
signed char VarA;
signed char VarA;
signed long VarA;
Total+=VarA*VarB;
The vast majority of cases, at least one of the variables VarA and VarB will be 0, so nothing will be added to Total.
Is there a way to check for this condition which might give me a performance increase over doing a lot of multiplying-by-zeros?
View 6 Replies
View Related
Sep 10, 2013
I am having trouble understanding how this loops would work. Give the function (x*x*x*x) - (10*x*x*x) + (35*x*x) - (50*x) + 24 Write a program that will use bisection method to find the roots of this function. Define lower limit and upper limit (e.g. -1.05 and 6.05) Starting at the lower limit step along the X axis at intervals of 0.1 for H calculating the function values f(x) and f(x +h), then f(x+h) and f(x+2h) until the upper limit is exceeded. If sign of the function value changes this indicates a root between ranges. Apply bi sectional method to this range until root has been found with an epsilon of 0.000001, then continue on until upper limit has been exceeded and all 4 roots found. If the function is within 0.000001 of zero then root has been found therefore no need for bi sectional method.
Code:
#include "stdafx.h"
#include "math.h"
#define H 0.1
#define epsilon 0.000001
double F(double x);
int main(void)
[code]....
So we have a function and a range. Program requires to work along the X axis at 0.1 increments until it reaches a point where the value changes from positive to negative or negative to positive. Then apply bisection method within that range to a given accuracy then print that root. Then continue on X axis until the next change of sign is found.
View 8 Replies
View Related
Jan 22, 2014
How do to calculate the following equation"5+((56+8)/2)" using expression builder
Note: the equation may change "50+((26+8)/12)"
View 1 Replies
View Related
May 11, 2013
I am working on a program to find the value of the current in a coil. This value satisfies the following equation:
y'=sin(2t)-[(ey-1)/(ey+1)]
which is of the form y'=f(t,y)
I know that in order to solve this I need to use the trapezoidal method to solve a differential equation, the formula is:
yn+1=yn+.5*h(f(tn,yn)+f(tn+1,yn+1) where h=tn+1-tn
I have found examples of the standard trapezoidal method but I do not think they will work because of the difference in the formulas.
View 2 Replies
View Related
Mar 29, 2013
My program is returning NaN even though the value in square root function is not negative -1*b + ((sqrt(pow(b,2) * -4 *(a*c))) / 2).
x = 10;
y = -1;
z = 1;
Heres the program:
main.cpp:
#include <iostream>
#include "Quad.h"
double x,y,z; // variable x = 'a', variable y = 'b' and variable z = 'c'.
[Code] ....
I would like it return the answer and not "NaN".
View 10 Replies
View Related
May 14, 2014
I've written a program that finds the maximum of a function. I now want to change it a little so that instead of evaluating the function y=x^2-7x-18, the program will ask the user to input an equation and then evaluate that equation. I'm really not sure of how to do so.
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
int a, b, delta, x, y;
double max= -1.8 * pow(10, 308);
[Code] .....
View 3 Replies
View Related