GithubHelp home page GithubHelp logo

sympy_mathcad's Introduction

sympy mathcad

Motivation

Inspired by https://github.com/mkhan45/CalcuLaTeX.

Wanted something that solved equations as well.

Based on sympy. Utilizes sympy’s solve function. Supports sympy syntax like units, pi, integrals and so on. Works well enough. Software is in “get something working” state. Good enough for my purpose.

Look at tips before using.

has both repl and input file version.

Usage

./sympy_mathcad.py
  • opens repl
./sympy_mathcad.py input-file
  • read and evaluate input-file
./sympy_mathcad.py term <<
  • read from stdin and evaluate. input through here-doc.

Tips

  • Press Enter to enter equations in mathcad like format. can be used to enter multi line equations. This is useful for keeping history intact.
  • Press Alt-Enter or C-r to evaluate equations. Needs to be preceded by an Enter.
  • Press C-f to flush or clear currently entered equations.
  • Press C-s to show or print currently entered equations.
  • Press C-c or C-q or C-d to quit.
text based
  • Enter any substring of “evaluate” to evaluate equations.
  • Enter any substring of “clear” to clear currently entered equations.
  • Enter any substring of “print” to see currently entered equations.
  • Enter any substring of “quit” to quit.

Examples

run in REPL

simple example

y = 3 * x
y = 10
x = ?
RESULTS
[x]
[{y: 10, x: 10/3}]
[{x: y/3}]
x  =  3.333

define and use units

in REPL ./sympy_mathcad.py

letter = Quantity("letter");
word = Quantity("word");
word.set_global_relative_scale_factor(5,letter);

gpt_size = 45e12*bit
file_size = 304e5*bit
file_words = 48902*word
gpt_words / gpt_size = file_words / file_size
gpt_words = ?
gpt_words = ? letter
e
Result
[{file_size: 30400000.0*bit, file_words: 48902.0*word, gpt_size: 45000000000000.0*bit, gpt_words: 72387828947.3684*word}]
[{gpt_words: file_words*gpt_size/file_size}]
gpt_words  =  7.239e+10*word
gpt_words  =  3.619e+11*letter

Numerical

caveats
  • each variable needs to be defined with ?.
  • need to a guess for value after “~” after “?”.
lasting_component = b * x * 1.30 ^ ( x / 12 )
temp_component = n * x * 1.30 ^ ( x / 12 )
130000 = temp_component
650000 - 130000 = lasting_component + (10400 - 6871 + 1105) * ( last - x ) * 1.30 ^ (( last - x ) / 12)
n + b = 1105
last = 100
n = ? ~ 100
b = ? ~ 100
last = ? ~ 144
lasting_component = ? ~ 100000
temp_component = ? ~ 130000
x = ? ~ 60
Result
-trying numerical solve--
[{n: 493.329807256738, b: 611.670192743262, last: 100.000000000000, lasting_component: 161184.513659930, temp_component: 130000.000000000, x: 64.4261206872098}]
n  =  493.3
b  =  611.7
last  =  100.0
lasting_component  =  1.612e+5
temp_component  =  1.300e+5
x  =  64.43

inequalities

caveats
  • doesn’t work with multiple variable equations
  • returns an Eq object
  • doesn’t use units
x > 0
3423 = x ^ 4
x = ? mile
Result
Eq(x, 3423^(1/4))
Eq(x, 3423^(1/4))
x  =  Eq(x, 3423^(1/4))

Integrals

pu = integrate( 3 * x, x ) + x *newton
x = 20*newton
pu = ?
Result
{pu: 620*newton**2, x: 20*newton}]
[{pu: newton*x + 3*x**2/2}]
pu  =  620.0*newton**2

Integrals(2)

pu *newton = integrate( 3/newton * x, x ) + x
x = ?
Result
[{pu: x*(2*newton + 3*x)/(2*newton**2)}]
[{x: newton*(-sqrt(6*pu + 1)/3 - 1/3)}, {x: newton*(sqrt(6*pu + 1)/3 - 1/3)}]
x  =  newton*(-0.8165*(pu + 0.1667)**0.5 - 0.3333)

Diff eq

f = Function('f');
Derivative(f(x), x, x) + 9*f(x) = 0
f(x) = ?
Result
[Eq(9*f(x) + Derivative(f(x), (x, 2)), 0)]
[{f(x): C1*sin(3*x)/3 + C2*cos(3*x)/3}]
f(x)  =  0.3333*C1*sin(3*x) + 0.3333*C2*cos(3*x)

sympy_mathcad's People

Contributors

natask avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.