Ask Your Question

Ondra's profile - activity

2021-12-15 23:10:42 +0200 received badge  Popular Question (source)
2019-05-13 23:56:50 +0200 received badge  Popular Question (source)
2019-03-09 01:47:49 +0200 received badge  Taxonomist
2016-01-10 15:49:50 +0200 received badge  Famous Question (source)
2014-12-13 23:31:05 +0200 received badge  Famous Question (source)
2014-08-28 17:32:39 +0200 received badge  Famous Question (source)
2014-06-29 03:14:54 +0200 marked best answer Substituting function value in an expression

I have an expression like uR(t) == 3*iL(0) + uC(0)/2 - 4

how can I substitute for iL(0) and uC(0), if I'm given, that iL(0) = 0 and uC(0) = 0.

uR, iL, uC are a functions of var t:

t = var('t')
uR = function('uR', t)
iL = function('iL', t)
uC = function('uC', t)

thank you :)

2014-06-10 14:03:05 +0200 received badge  Notable Question (source)
2014-05-22 12:13:36 +0200 received badge  Famous Question (source)
2013-12-05 17:04:16 +0200 received badge  Popular Question (source)
2013-10-07 13:06:21 +0200 received badge  Notable Question (source)
2013-08-17 20:54:23 +0200 received badge  Notable Question (source)
2013-03-04 23:07:54 +0200 received badge  Popular Question (source)
2012-11-23 12:37:43 +0200 received badge  Notable Question (source)
2012-11-18 17:29:15 +0200 received badge  Popular Question (source)
2012-04-18 05:16:22 +0200 received badge  Popular Question (source)
2011-09-16 15:27:18 +0200 asked a question Plotting a loglogplot

is there a way to create a loglogplot? (a 2D plot that has both axes logarithmically scaled)

I've found links to there bugs (0, 1), but this hasn't been much helpful.

2011-09-16 15:19:36 +0200 answered a question Difference between U and U(t)

the link above _does_ answer my question. hurray :)

2011-09-16 15:19:13 +0200 answered a question Symbolic variable declaration

the link above _does_ answer my question. hurray :)

2011-09-16 15:05:06 +0200 commented answer How to make solve to use certain variables on the right side

yes! factor() is what I was looking for. but this returns "(R1 + R2)*U1/(R1*R2)". can I make it somehow to return "I1 == (R1 + R2)*U1/(R1*R2)"? from the documentation, it seems that factor only is method of expressions, not equations.

2011-08-01 21:24:18 +0200 commented answer Can desolve_system return dict?

yes, this solves it, so thanks much; but anyway, this is a reasonable thing to want from desolve_system, so do you think I should file a bug/feature request for desolve_system to accept solution_dict parameter?

2011-08-01 21:23:55 +0200 marked best answer Can desolve_system return dict?

Unfortuantely, desolve_system doesn't take a solution_dict parameter -- you can do desolve_system?? to see that it doesn't take that keyword argument. Luckily, it's easy to make such a function that returns the solutions in a dictionary.

def desolve_system_dict(*args, **kwds):
    use_dict = kwds.pop('solution_dict', False)
    solution = desolve_system(*args, **kwds)
    if use_dict:
        return dict((eq.lhs(), eq.rhs()) for eq in solution)
    else:
        return solution

Then you can use it like this:

sage: t = var('t')
sage: x = function('x', t)
sage: y = function('y', t)
sage: de1 = diff(x,t) + y - 1 == 0
sage: de2 = diff(y,t) - x + 1 == 0
sage: desolve_system_dict([de1, de2], [x,y])
[x(t) == (x(0) - 1)*cos(t) - (y(0) - 1)*sin(t) + 1,
 y(t) == (x(0) - 1)*sin(t) + (y(0) - 1)*cos(t) + 1]
sage: desolve_system_dict([de1, de2], [x,y], solution_dict=True)
{y(t): (y(0) - 1)*cos(t) + (x(0) - 1)*sin(t) + 1, 
 x(t): -(y(0) - 1)*sin(t) + (x(0) - 1)*cos(t) + 1}
2011-07-31 13:57:48 +0200 asked a question Symbolic variable declaration

what is the difference, when I declare variable like this

a, b, c = var('a, b, c')

or just like this

var('a, b, c')

?

2011-07-30 20:38:30 +0200 asked a question Difference between U and U(t)

If I have

t = var('t')
U = function('U', t).function(t)

what is the difference between the expression U and U(t). When should I use which?

2011-07-29 20:54:02 +0200 asked a question Can desolve_system return dict?

I know the parameter solution_dict=True for solve

but quick try for desolve_system(equations, unknowns, ics=initials, solution_dict=True) gives an error

desolve_system() got an unexpected keyword argument 'solution_dict'.

Is there a way?

2011-07-29 19:56:54 +0200 asked a question How to make solve to use certain variables on the right side

if I have

I1, IR1, IR2, U1, R1, R2 = var('I1 IR1 IR2 U1 R1 R2')
equations = [
I1 == IR1 + IR2,
IR1 == U1/R1,
IR2 == U1/R2
]

how can I make solve to return

I == (R1 + R2)*U1/(R1*R2)

?

solve(equations, I)

now returns just an empty list

or similait problem is with

I1, IC1, IC2, U1d, U2d, C1, C2 = var('I1, IC1, IC2, U1d, U2d, C1, C2')
equations = [
I1 == IC1 + IC2,
IC1 == C1*U1d,
IC2 == C2*U1d
]

and desired result is

I1 == (C1 + C2)*IC2/C2
2011-07-28 15:41:57 +0200 marked best answer Solving symbolically equation system

As far as I know, solve only works with variables. So as a preliminary step you can substitute some new variables for I.diff(t) and uC.diff(t) and then solve. The other problem occuring is that to solve a system of equations for multiple variables, those variables should be specified as a list. Try this: (first substitute new variables DI and DuC for the two derivatives and then call solve)

sage: E2 = [ e.subs({I.diff(t): DI, uC.diff(t): DuC}) for e in equations ]
sage: E2
[t |--> U(t) == 0.100000000000000*DI + 6*I(t) + uC(t), t |--> I(t) == 1/10000*DuC]
sage: solve(E2, [DI, DuC])
[[DI == 10*U(t) - 60*I(t) - 10*uC(t), DuC == 10000*I(t)]]
2011-07-23 21:24:08 +0200 asked a question Solving symbolically equation system

I have an equation system:

U(t) = R * I(t) + L * I'(t) + uC(t)

I(t) = C * uC'(t)

I want to know value of I'(t) and uC'(t), which is (-I(t) * R + U - uC(t))/L and I(t)/C respectively.

In sage I represent it this way:

R = 6; C = 10^(-4); L = 0.1
t = var('t')
U = function('U', t).function(t); I = function('I', t).function(t); uC = function('uC', t).function(t)

equations = [
U == R * I + L * I.diff(t) + uC,
I == C * uC.diff(t)
]

but

solve(equations, I.diff(t), uC.diff(t))

does't seem to be working. (TypeError: 'sage.symbolic.expression.Expression' object is not iterable)

why? how can I do this?

2011-07-07 19:12:55 +0200 received badge  Supporter (source)
2011-07-01 11:12:11 +0200 marked best answer Substituting function value in an expression

Expanding on my remark:

Functions defined in the way above don't say they have just one variable for input (their expression could, in theory, have some constants like c or a that shouldn't be substituted, only t), so we have to do this:

sage: t = var('t')
sage: uR = function('uR', t).function(t)
sage: iL = function('iL', t).function(t)
sage: uC = function('uC', t).function(t)
sage: SE = uR(t) == 3*iL(0) + uC(0)/2 -4
<no deprecation message>
2011-07-01 11:12:08 +0200 marked best answer Substituting function value in an expression

The simplest way is just to use the subs (or substitute) method of your symbolic expression like so:

sage: t = var('t')
sage: uR = function('uR', t)
sage: iL = function('iL', t)
sage: uC = function('uC', t)
sage: 
sage: SE = uR(t) == 3*iL(0) + uC(0)/2 - 4
sage: SE.subs(iL(0)==0)
uR(t) == 1/2*uC(0) - 4
sage: SE.subs(uC(0)==0)
uR(t) == 3*iL(0) - 4
sage: SE
uR(t) == 3*iL(0) + 1/2*uC(0) - 4

You see from the last line that the object SE is not changed during the substitution, so you should assign the result of the substitution. Also, you can do both (or arbitrarily many) substitutions using a dictionary:

sage: R = SE.subs({iL(0):0, uC(0):0})
sage: R
uR(t) == -4
2011-07-01 11:12:08 +0200 received badge  Scholar (source)
2011-07-01 11:11:57 +0200 commented answer Substituting function value in an expression

thanks a lot! :)