First time here? Check out the FAQ!

Ask Your Question
1

How to show that two given functions are linearly dependent

asked 4 years ago

Presto.creator gravatar image

Is there a way with sage to show if two given functions are linearly dependent? Like if I have

f(x) = 17, g(x) = cos^2(x), h(x) = cos(2x)

Then sage could either give me the constants that would show they are linearly dependent, or say they aren't

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 4 years ago

Juanjo gravatar image

updated 4 years ago

Let f1,,fn be functions defined on a given interval I and n1 times differentiable. Let W(f1,,fn) be the Wronskian of these functions. It is well known that:

if f1,,fn are linearly dependent on I, then W(f1,,fn) vanishes on I.

In general, the converse is not true: the vanishing of the Wronskian on I does not imply that the functions are linearly dependent. However, if f1,,fn are analytic, then these functions are linearly dependent on I if and only if W(f1,,fn)0 on I.

Since f(x)=17, g(x)=cos2(x) and h(x)=cos(2x) are analytic on R, we can check if they are linearly dependent by testing their Wronskian:

sage: f(x) = 17 
sage: g(x) = cos(x)^2 
sage: h(x) = cos(2*x) 
sage: funs = [f(x),g(x),h(x)] 
sage: bool(wronskian(*funs,x)==0)                                               
True

Thus, f, g and h are linearly dependent.

Preview: (hide)
link
1

answered 4 years ago

slelievre gravatar image

updated 4 years ago

First an answer for the special case, then a more general answer.

Trigonometric functions

In the special case of the example in the question, this helps:

sage: f(x) = 17
sage: g(x) = cos(x)^2
sage: h(x) = cos(2*x)

sage: h(x).simplify_trig()
2*cos(x)^2 - 1

Linear independence of functions

Returning to the general question, one way to check for possible linear dependence relations, or for proofs of independence, would be to project to a finite-dimensional subspace and check there.

Form a vectors from the value of each function at a chosen collection of evaluation points.

If these vectors are linearly independent, then the functions are.

If there is a linear relation between these vectors, then it's worth checking if the linear relation in fact holds for the functions themselves.

Let us illustrate with the three functions above.

Choose a collection of evaluation points:

sage: xx = (0, pi/6, pi/4, pi/3, pi/2)

Form a vector for each function:

sage: u = vector([f(x) for x in xx])
sage: v = vector([g(x) for x in xx])
sage: w = vector([h(x) for x in xx])

To look for dependence relations, compute the left kernel of the matrix with these vectors as rows.

sage: m = matrix([u, v, w])
sage: K = m.kernel()
sage: K
Vector space of degree 3 and dimension 1 over Algebraic Real Field
Basis matrix:
[  1 -34  17]

This suggests that maybe f - 34*g + 17*h is zero.

Extract the coefficients:

sage: a, b, c = K.basis()[0]
sage: a, b, c
(1, -34, 17)

Check if the linear relation in fact holds for the functions:

sage: bool(a*f(x) + b*g(x) + c*h(x) == 0)
True
Preview: (hide)
link

Comments

Thank you so much!

Presto.creator gravatar imagePresto.creator ( 4 years ago )

Hi again! I tried using the method you showed, but instead of getting a clean answer, I get "unable to convert pi to an element of Algebraic Real Field"

using

 f(x)=6*x
g(x)=2*x^2
h(x)=6*x-5*x^2
xx=(0,pi/6,pi/4,pi/3,pi/2)
u=vector(AA,[f(x) for x in xx])
v=vector(AA,[g(x) for x in xx])
w=vector(AA,[h(x) for x in xx])
m=matrix([u,v,w])
K=m.kernel()
show(K)

Any thoughts on if I did the code wrong?

Presto.creator gravatar imagePresto.creator ( 4 years ago )
1

You did nothing wrong.

Choosing xx = (0, pi/6, pi/4, pi/3, pi/2) gave algebraic values for the cosines so my original answer hardcoded constructing vectors over the algebraic numbers.

Using vector([...]) (as in edited answer) instead of vector(AA, [...]) (as in original answer) works both for original example and new one.

slelievre gravatar imageslelievre ( 4 years ago )

Is there a way to have it show a clean answer, like in your first reply to my question instead of something like

Vector space of degree 3 and dimension 1 over Symbolic Ring
Basis matrix:
[                            1 -15/2/(pi + (7*pi - pi^2)/pi)    -5/(pi + (7*pi - pi^2)/pi)]

I know that might be one answer but it's not helpful when finding non-trivial linear combinations lol

Presto.creator gravatar imagePresto.creator ( 4 years ago )

For three functions that are polynomials with integer coefficients, xx = (0, 1, 2, 3, 4, 5) might be a more natural choice of evaluation points.

slelievre gravatar imageslelievre ( 4 years ago )

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

Stats

Asked: 4 years ago

Seen: 1,533 times

Last updated: Mar 27 '21