Ask Your Question

Trouble finding intersection of two functions

asked 2018-10-22 00:51:55 -0600

lgushurst gravatar image

Hi all,

I'm still pretty new using SageMath, but I'm trying to duplicate functionality that I've been able to do in wolfram alpha

Wolfram Input:

Intersection points of [//math:90000 1.03^x//] and [//math:63000 1.095^x//]

So far I've been able to recreate and graph these functions very easily using SageMath, but I'm having a difficult time using the solve function to actually return a numerical value for the intersection point itself.

My SageMath code looks like:

x = var('x') 
f1 = (63000*((1.095)^x))
f2 = (90000*((1.03)^x))
print ans 
print n(ans[0].rhs())

ans prints as "[ 219^x == 1/35200^(x - 1)103^x*100^(-x + 2) ]"

And I get an error "TypeError: cannot evaluate symbolic expression numerically" in my attempts to resolve it to an approximate number.

Can anyone tell me what I'm doing wrong?

edit retag flag offensive close merge delete


  1. Is this homework ?
  2. What set $x$ is supposed to belong to ?
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-10-22 07:37:05 -0600 )edit
  1. It's not homework, I'm just learning SageMath
  2. I didn't think x needed to be part of a set, there's only one intersection point and it's at roughly ~5.82. Are you saying I need to set this problem up in another way?
lgushurst gravatar imagelgushurst ( 2018-10-22 07:45:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-10-22 09:25:36 -0600

Emmanuel Charpentier gravatar image
It's not homework, I'm just learning SageMath

Okay. If you lied, may you live in interesting times (e. g. cross-examination by your instructor...)

I didn't think x needed to be part of a set,

Really ? That means that we'll work in an "elementary" (high school) point of view, and consider searching for real solutions.

Being lazy, I'll start by minimizing typing. Store your equation in a Python variable :

sage: E=90000*1.03^x==63000*1.095^x ; E
90000*1.03000000000000^x == 63000*1.09500000000000^x

Try to solve it directly :

sage: E.solve(x)
[219^x == 1/35*200^(x - 1)*103^x*100^(-x + 2)]

Sage tells us that there may exist a solution, which would satisfy this equation, which is, in some way, a restatement of our original equation (sage replaced your floating-pont numbers by close approximations expressed as "simple" fractions, an interesting step I won't discuss here...). This implicit solution isn't good enough for us.

Let's try to get rid of the powers ; to this end, we'll take the logarithms of both members of the equation, thus mapping our powers to products (see Wikipedia for an explanation if needed). The logarithm being monotonic on the set of positive real numbers, this will get you the same solution(s), if any.

Sage allows us to shortcut that by applying the log method to the equation :

sage: E.log().solve(x)
[log(9*103^x*100^(-x + 2)) == log(315*219^x*200^(-x + 1))]

Well... this worked only partially : Sage did not expand the logarithms of both sides, and still leaves us with an implicit equation. Let's do it ; again, Sage allows us to apply the log_expand method to both sides of the equation :

sage: E.log().expand_log()
0.02955880224154443*x + log(90000) == 0.09075436326846412*x + log(63000)

Now, this is a first degree linear equation, that Sage can solve :

sage: E.log().expand_log().solve(x)
[x == 91739056/5614023*log(90000) - 91739056/5614023*log(63000)]

Sage tells us that if finds one solution, which it gives us as "exactly" as it can. Oh, you were expecting a numerical approximation of the value ? Here it comes :

sage: E.log().expand_log().solve(x)[0].rhs().n()

Now, is this solution the solution ? Maybe not. You see, there are more in maths than real numbers ; $x$ may be a complex number, whose logarithm is a horse of a totally different color.

But discussing the nature and number of solution(s) of your equation is left to you, dear reader.

But beware : to be rigorous, this discussion needs sophomore-level analysis. Logarithms of real numbers were more or less understood by the beginning of the XVIIth century, while correct comprehension of complex analysis had to wait for the XIXth century, and is closely related to still open problems.

edit flag offensive delete link more


I've accepted your answer as the solution and really appreciate the explanation, it's incredibly thorough and helped me understand the context of what I was attempting to do more clearly.

lgushurst gravatar imagelgushurst ( 2018-10-22 11:25:51 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-10-22 00:51:55 -0600

Seen: 115 times

Last updated: Oct 22 '18