# Gregory Bard's profile - activity

2020-08-05 01:09:56 +0200 asked a question Sage fails to recognize 1 + (1/2 + i*sqrt(3)/2)^3 is zero

The following code:

print( 1 + ( 1/2 + i*sqrt(3)/2 )^3 )
print( simplify( 1 + ( 1/2 + i*sqrt(3)/2 )^3) )
print( N(1 + ( 1/2 + i*sqrt(3)/2 )^3) )


Results in the output:

(1/2*I*sqrt(3) + 1/2)^3 + 1
(1/2*I*sqrt(3) + 1/2)^3 + 1
2.22044604925031e-16 + 1.11022302462516e-16*I


but I'd expect the middle one, and perhaps even the first one, to be just "0." I think this means that there is something which I don't understand about how these expressions are handled.

2020-07-01 01:28:17 +0200 asked a question Strange Error Message when Plotting with a LaTeX Legend

The following code is from the 1st edition of my textbook, Sage for Undergraduates. It is producing some extremely unexpected errors (technically, deprication warnings). Something about an invalid escape sequence, \i, which I'm not using.

Can someone explain how I should change my code, so that these warnings do not appear?

Code:

P1= text('$\int_0^2 \sqrt{x} \, dx$', (0.5, 1.1), fontsize=20)

P2= plot( sqrt(x), 0, 2, fill=True)

P= P1 + P2

P.show()

Warning: <input>:1: DeprecationWarning: invalid escape sequence \i

2014-07-21 19:26:25 +0200 asked a question Video for Sage Cell ---> Sage Cloud conversion?

I was wondering if anyone has made a video to help students transition from using the Sage Cell Server (for simple tasks) to the Sage Cloud system?

I'm thinking of something very short, to give flavor and "the basics." Perhaps something 5-10 minutes long suitable for 200-level math, physics and engineering majors.

2014-07-21 19:15:59 +0200 commented answer solving implicit equation

I'm guessing that you need either the Taylor expansion or some competitor of it, like the Chebychev polynomials. The main issue is that you have both sin x and a linear polynomial in x. Therefore, I really can't see how you would "solve for x." I'm about 98% sure but I don't want to say 100%, because mathematics is always full of surprises.

2014-07-20 19:58:38 +0200 answered a question solving implicit equation

One option, and this might be suboptimal, is to replace sin(x) with its taylor series.

Because

sin(x) = x - (1/6)x^3 + (1/120)x^5 - (1/5040)x^7 + (1/362880)x^9 - O(x^11)

we would change

Asin(x) = BC - B*x

Ax - (A/6)x^3 + (A/120)x^5 - (A/5040)x^7 + (A/362880)x^9 - O(A x^11) = BC - Bx

giving you then

-BC + (A+B)x - (A/6)x^3 + (A/120)x^5 - (A/5040)x^7 + (A/362880)x^9 - O(A x^11) = 0

or if you want a few more terms

-BC + (A+B)x - (A/3!)x^3 + (A/5!)x^5 - (A/7!)x^7 + (A/9!)x^9 - (A/11!)x^11 + (A/13!)x^13 + O(A x^15) = 0

This does reveal that varying C will only affect the answer by a constant.

If A and B were fixed constants, known in advance, then you could use "for" and "find_root" to find a value of x for a long sequence of C values, forming a table of values.

For example:

http://sagecell.sagemath.org/?z=eJxtk...

2014-07-19 00:36:53 +0200 answered a question How Do I Extract Terms Containing Certain Coefficients From A Polynomial?

# Quick Question

...Did you intend I_L and i_L to be distinct? did you intend D and d to be distinct? how about v_C and V_C? In Sage, the capitalization matter, and these would be treated as distinct.

# Solution

Assuming that you wanted them to be distinct, the following will work:

var("D I_L Ron d i_L V_g v_g V_C n v_C")

f = -DI_LRon - I_LRond - DRoni_L - Rondi_L + DV_g + V_gd + Dv_g + dv_g + DV_C/n + V_Cd/n + Dv_C/n + dv_C/n - V_C/n - v_C/n

print "Before:"

print f

print "After:"

print f(i_L=0, d=0, v_g=0, v_C=0)

# Output

Before:

-DI_LRon - I_LRond - DRoni_L - Rondi_L + DV_g + V_gd + Dv_g + dv_g + DV_C/n + V_Cd/n + Dv_C/n + dv_C/n - V_C/n - v_C/n

After:

-DI_LRon + DV_g + DV_C/n - V_C/n

2014-07-19 00:17:00 +0200 answered a question Simultaneous Linear Equations Help

The author of this question intends for you to plug 5 in for x and k in for y. If you do this, you will obtain

2(5) + k - 7 = 0

10 + k - 7 = 0

3 + k = 0

k = -3

We can check our work by confirming that (5, -3) is a solution to 2x + y - 7 = 0.

2(5) + (-3) - 7 = 10 - 3 - 7 = 7 - 7 = 0.

Using what you find there, try to solve this one yourself.

# To do this in Sage, I tried the following, which worked:

var("x y") solve( [11x+15y+23 ==0, 7x-2y-20 == 0], [x,y] )

# However, I'm wondering if what you really want to know is how to do this by hand... If so, please consider reading

• Ch 1, Sec 2 "Intersecting Two Lines, Part One"
• Ch 1, Sec 3 "Intersecting Two Lines, Part Two"

# of my free electronic online textbook-in-progress for the freshmen math course that business majors take: "Finite & Financial Mathematics for University Freshmen." All you have to do is:

• Go to www.gregorybard.com
• Click on "Finite Math" on the left hand side of the page
• Each section is its own pdf file.
2014-07-18 22:53:59 +0200 answered a question generate_plot_points for multiple variable functions and contour_plot

The function you are looking for is contour_plot. The following works:

var("y")
contour_plot( y^2 - x^3 - x == 0, (x,-5,5), (y,-5,5), fill=False, axes=true )

2014-07-18 22:51:01 +0200 answered a question 4x+6/y=15,6x-8/y=14 : y is not equal to zero Find p, if y=px-2

# I tried the following:

var("x y p")

solve( [ 4x + 6/y == 15, 6x - 8/y == 14, y == p*x - 2 ], [p, x, y] )

# that produces the response

[[p == (4/3), x == 3, y == 2]]

# which appears to be correct.

2014-07-04 07:09:06 +0200 answered a question .sage does not exist?

Personally, I think it is a serious mistake to install Sage locally on a personal computer. The Sage Cloud interface is far easier to use, requires no installation (it works through the web browser), and it brings you all the advantages of cloud computing---for example, your data lives forever on a server even if your laptop suffers some grave mishap. There are many features for sharing your work with others, and so forth. There's just no reason to bother with a local install.

https://cloud.sagemath.com/

Even simpler is the Sage Single-Cell Server which is great for small Sage tasks.

https://sagecell.sagemath.org/

2014-07-03 22:52:17 +0200 commented question function minimize cannot solve Lagrange Multipliers problem.

calc314, I'm sorry, but that's not correct. See where it says "Current function value: 2.032982"? That should be zero. Also, it does not match the symbolic solution at all. Perhaps this is a bug, and minimize should give an error message, since the minimum wasn't reached?

2014-07-03 22:49:13 +0200 commented question function minimize cannot solve Lagrange Multipliers problem.

rws, I'm not sure where the plus signs went. They definitely belong. It must have been an error during cut-and-paste. I was using the Sage Single-Cell Server.

2014-07-03 22:48:04 +0200 answered a question function minimize cannot solve Lagrange Multipliers problem.

%% step one: var("y z L")

F(x, y, z, L) = (x-3)^2 + (y-1)^2 + (z+1)^2 + L*(x^2 + y^2 + z^2 - 4)

derivative(F)

%% step two:

eqn1= 2Lx + 2*x - 6 == 0

eqn2= 2Ly + 2*y - 2 == 0

eqn3= 2Lz + 2*z + 2 == 0

eqn4= x^2 + y^2 + z^2 - 4 == 0

solve( [eqn1, eqn2, eqn3, eqn4], [x, y, z, L] )

%% correct answer obtained: [[x == -6/11sqrt(11), y == -2/11sqrt(11), z == 2/11sqrt(11), L == -1/2sqrt(11) - 1],

[x == 6/11sqrt(11), y == 2/11sqrt(11), z == -2/11sqrt(11), L == 1/2sqrt(11) - 1]]

%% moral of the story: if symbolic methods work fine, why bother with numerical methods?! ;-)

2014-07-03 03:41:37 +0200 answered a question convex objective function with linear constraint

if f(x1,x2,..,xn) is convex (or concave) then minimizing or maximizing subject to the linear constraint g(x1,x2,..,xn)=0 should be the same as minimizing or maximizing

F(x1,x2,...,xn,L) = f(x1,x2,...xn) + L*g(x1,x2,...,xn)

in the unconstrained sense. See "minimize?" for help. Convex functions (or concave) functions will have a unique minimum (or unique maximum), so everything should work out.

2014-07-03 03:35:21 +0200 asked a question function minimize cannot solve Lagrange Multipliers problem.

I've tried all sorts of initial conditions but this just won't converge. It is an easy Lagrange multipliers problem.

var("y z L")
F(x, y, z, L) = (x-3)^2 +  (y-1)^2 +  (z + 1)^2 +  L*(x^2 +  y^2 +  z^2 - 4)
minimize(F, [4, 3, 2, 1], algorithm='ncg' )


Any thoughts? Are there ways of forcing it to use more iterations, or something??