1

So i have two functions defined as f(x)=x^2-x-6 and g(x)=x+2 I need to find the points where f(x)=g(x) When i

solve(f(x)=g(x),x)

i get two values; x=-2 and x=4 My question is, can i define the two values individually from the solve so i get x1=-2 and x2=4 ? I've tried getting the text out as a string using string(solve and a version of res:=solve({x+2*y=5,x-y=2},{x,y}) from another post. But this doesn't seem to work for me. Thanks!

Rasmus Bak
  • 11
  • 2

2 Answers2

1

Let's try step by step:

f:=x^2-x-6
g:=x+2
res:=solve(f=g,x)

ans: x=−2 or x=4

l1:=exp▶list(res,{x})

ans: [[4][−2]] At what step are you failing and what error youre getting?

fragg
  • 351
  • 1
  • 7
  • The thing i can't seem to figure out with this method is when i define x1=-2 and x2=4 it gets written as x1=[-2] and x2=[4] and therefore i can't use them for further calculations in my document. For context i am trying to use x1 and x2 for definite integral, and when i try to input them in definite integral i get the error "Argument error" – Rasmus Bak Oct 02 '19 at 09:06
  • Yeah, it packs them like a matrix, not vector. So, you can type: x1:=l1[1,1] and x2:=l1[2,1] to get scalars. – fragg Oct 02 '19 at 19:04
  • This was exactly what i was looking for, and i got it working now. Thank you so much for your help! Really appreciated! – Rasmus Bak Oct 03 '19 at 16:46
  • Ok, but in this case (if youre sure that f and g are both polynomials), i think that polyroots is faster: li:= polyroots (f-g,x): x1:= li[1]: x2:= li[2] – fragg Oct 04 '19 at 17:58
0

Hej Rasmus,

The simplest solution is to use zeros which finds zeros (nulpunkter) of a function. Two functions f(x) and g(x) are equal, when their difference is zero.

f(x) = g(x)    <=>   f(x)-g(x) = 0

You can find the solutions like this:

zeros(f(x)-g(x))

And to store them in variables:

xs := zeros( f(x)-g(x) )
x1 := xs[1]
x2 := xs[2]
soegaard
  • 30,661
  • 4
  • 57
  • 106
  • Thanks for the quick response! This works! But do you know of a way to get the two results defined separately from the solve command? Or is the only way to find a work around each time? – Rasmus Bak Oct 02 '19 at 08:59
  • What do you mean by separately here? You can, write `zeros( f(x)-g(x))[1]` and `zeros(f(x)-g(x))[2]` but that it is inefficient (it will solve the equation twice). – soegaard Oct 02 '19 at 09:56
  • Sorry for being unclear, english is not my first language. I will try to explain myself as good as possible. What i mean is if i have an equation, with more than one answer, that i have to use `solve` to solve and zeros can't be applied, is there a way to define them individually like zeros( f(x)-g(x))[1] and zeros(f(x)-g(x))[2] but instead something like `solve(f(x)-g(x),x)[1]` and `solve(f(x)-g(x),x)[2]` (I know these two solve solutions do not work, but i hope it shows what i am trying to accomplish to learn to do in TI-Nspire) – Rasmus Bak Oct 02 '19 at 11:35
  • The difference between `solve` and `zeros` is that `solve` gives you an expression (udtryk) as a result, like `x=42`, and `zeros` gives you a list of roots `{42}`. Since you want to store the solution `42` it is easier to use `zeros` than `solve` since `zeros` give you the numbers directly. Now given an expression like `x=42` you can use `right` to get the number. What complicates matters is that you have multiple solutions. Therefore you need to use `exp▶list` first to turn the result of `solve` into a list, then use `right`. Note that internally `solve(f(x)=g(x),x)` just calls `zeros`. – soegaard Oct 02 '19 at 11:43
  • In short, the situation "i have an equation, with more than one answer, that i have to use solve to solve and zeros can't be applied" is a bit silly - why not use `zeros`? (If you are worried that a reader doesn't get - simply add a line explaining what it does). – soegaard Oct 02 '19 at 11:45
  • I thank you for your time and on the insight of TI-Nspire, you were a giant help! – Rasmus Bak Oct 02 '19 at 12:20