带有交感的基本代数:将系数和变量保持在一起

时间:2016-06-16 22:51:15

标签: python sympy

我试图用一些基本的代数和物理来表达对象。定义诸如

之类的等式时
import sympy as sy
g,h = sy.Symbols("g h")
v = sy.sqrt(2 * g * h)

等式v扩展到

v = sqrt(2) * sqrt(g * h)

有一种方法可以指定系数" 2"不应该被考虑在内 在平方根下,sqare根下的项保持为" 2 * g * h"?我想这样做的原因是基础物理学和得到的方程的推导有时更清楚,看看相关系数是否没有被考虑在内。

另一个例子就是计算像

这样的等式中的弧长度
phi = sy.symbols("phi")
r = sy.symbols("r")
a= r * phi

表示角度的两倍

phi = sy.pi / 4

,如

a = r * (2 * phi)

收集到

a = r * sy.pi / 2

a = r *  2 * (sy.pi / 4)

可能更清楚地显示结果是如何获得的。

1 个答案:

答案 0 :(得分:2)

  

有没有办法指定系数" 2"不应该是   从平方根和sqare下的术语中分解出来   root保持为" 2 * g * h"?

是的,只需使用可选参数 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/normalize.css"> <link rel="stylesheet" type="text/css" href="css/fonts.css"/> <link rel="stylesheet" href="../css/stylesheet.css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> </head> <body> <div id="wrapper"> <header> <img src="../images/banner.jpg"> </header> <div id="jobInterview"> <h1>Allied Health Assistant Job Interview</h1> <img src="../images/panelinterview.jpeg" alt="interview panel"> <h2>Answer the questions provided</h2> <p>Note: when the timer finishes it will reset for the next question until the interview is finished</p> <h2 id="message"></h2> <video id="myVideo" width="160" height="120" autoplay loop> <source src="../videos/timer.mp4" type="video/mp4" > Your browser does not support the video tag. </video> <script> var questions = [ "Question 1 <br> What interests you about this job?", "Question 2 <br>What new skills are you looking to develop as an allied health assistant? ", "Question 3 <br>Tell me about a successful team project that you have been involved in. What was your role and what made it a success?", "Question 4 <br>What is your greatest strength?", "Question 5 <br>What are you passionate about? " ]; var vid = document.getElementById("myVideo"); $( document ).ready(function() { function showQuestion() { if (questions.length == 0) { window.location.replace("../finish.html"); } else { $('#message').html(questions.shift()).fadeIn(500).delay(180000).fadeOut(500); } } }); function nextQuestion() { $('#message').html(questions.shift()).fadeIn(500).delay(180000).fadeOut(500); vid.currentTime=0; } </script> <button id="next-question" onClick="nextQuestion()">Next Question</button> </div> </div><!-----CLOSE WRAPPER DIV------> </body> </html> 创建Pow对象(加电):

evaluate=False

也就是说,>>> Pow(2*g*h, S(1)/2, evaluate=False) _______ \/ 2*g*h 2*g*h(一半)引发。 S(1)/2禁用对象构造期间的自动评估。