equationsolver

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2022 License: MIT Imports: 4 Imported by: 0

README

equation-solver

GitHub go.mod Go version GitHub tag (latest by date) GitHub

A program that will solve any linear, quadratic and cubic equation.

How to use it

  • Download the 'equationsolver' package:
go get -u github.com/Gabri432/equation-solver
  • Example of usage
package main

import (
    "fmt"
    eq "github.com/Gabri432/equation-solver"
)

func main() {
    solution := eq.EvaluateEquation("x^3-4x=5x^2-1")
    fmt.Println("real solutions: ", solution.RealSolutions, "\ncomplex solutions:", solution.ComplexSolutions)
    myPolynom := eq.Polynom{A: 1, B: 5, C: -4, D: 1}
    fmt.Println(myPolynom.SolveEquation())
}

=== Output ===

real solutions: [-0.8752... 0.2013... 5.6739...]

complex solutions: []

{[0.38196... 2.61803...] [] }

Functions

EvaluateEquations(equation string) EquationSolution
  • Takes the equation in form of string and returns the result of type EquationSolution
ValidateEquation(equation string) string
  • Checks if the user inserted equation is valid.

Types

Polynom
// Creates a polynom in the form: ax^3+bx^2+cx+d
type Polynom struct {
	A float64
	B float64
	C float64
	D float64
}
EquationSolution
type EquationSolution struct {
	RealSolutions    []float64    // set of real solutions
	ComplexSolutions []complex128 // set of complex solutions
	ErrorDescription string       // error message

Project Structure

  • (main)
    • equation.go
    • equation_test.go
    • internal_functions.go
    • internal_functions_test.go
    • license
    • README.md
    • README.it.md
    • .github
      • CONTRIBUTING.it.md
      • CONTRIBUTING.md

Contribuire al progetto

Notes

Documentation

Overview

The 'equationsolver' package allows to solve Linear, Quadratic and Cubic equations.

How to write an equation:

1) 'x' is the only variable you can use;

2) '^' is the symbol to indicate the powering, ex: x^3 is x powered 3.

Example:

x^3+x^2+3=3+x-2x^2 (valid)

y^2=x**2 (invalid)

If you need to report an issue go on https://github.com/Gabri432/equation-solver/issues/new

If you appreciate the work consider putting a star on https://github.com/Gabri432/equation-solver

Check its correctness with this link: https://www.calculatorsoup.com/calculators/algebra/cubicequation.php

This project is under the MIT license: https://github.com/Gabri432/equation-solver/blob/master/license

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateEquation

func ValidateEquation(equation string) (errorMessage string)

Check if the expression given is an actual equation.

It looks for:

- the presence of the '=' equal sign

- the absence of '**' (consecutives multiplication signs)

- the absence of '^^' (consecutives powering signs)

- the absence of '//' (consecutives division signs)

- the absence of 'xx' (consecutives variable signs)

Types

type EquationSolution

type EquationSolution struct {
	RealSolutions    []float64    // set of real solutions
	ComplexSolutions []complex128 // set of complex solutions
	ErrorDescription string       // error message
}

func EvaluateEquation

func EvaluateEquation(equation string) EquationSolution

It takes the user equation and solves it.

It can only take Linear, Quadratic and Cubic equations.

It returns the set of real solutions, complex solution, and eventually an error message.

type Polynom

type Polynom struct {
	A float64
	B float64
	C float64
	D float64
}

Creates a polynom in the form: ax^3+bx^2+cx+d

func (Polynom) SolvePolynom

func (p Polynom) SolvePolynom() EquationSolution

Returns polynom solutions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL