ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 09 Apr 2019 07:13:11 -0500function parameters as sum limitshttp://ask.sagemath.org/question/46060/function-parameters-as-sum-limits/ I am completely new to sage, so I am afraid that this should be a very standard well known issue. Sorry for that.
I need to define a function one of whose parameters is a limit of a sum.
I tried:
d,n,i = var('d,n,i')
def N(d,n):
if n==1:
return 1
else:
return sum(N(d,i),i,1,n-1)
But sage complains with a RuntimeError. Why is that? I suppose that for some reason the parameter `n` from the function is not assigned to the variable limit `n-1` in the sum. I this correct? How can I fix that?
suitTue, 09 Apr 2019 07:13:11 -0500http://ask.sagemath.org/question/46060/How can i estimate kinitic parameter of a steady-state reactor?http://ask.sagemath.org/question/44134/how-can-i-estimate-kinitic-parameter-of-a-steady-state-reactor/ i want to solve a system of ODE with some unknown parameters(k1,k2,k3): dC1/dx=-k1*C1/(1+k1*C1) ; dC2/dx=k1*C1/(1+k1*C1)-k2*C2 ; dC3/dx=k2*C2-k3*C3 ; and i have a set of experimental (4 experiment resulu) where values of C1,C2,C3 at x=0(inlet point) and x=1(end point). i don't have any data between x=[0:1] to solve it with ODE function like ode45 or ode23, ... and then use optimization function.how can i solve this problem in matlab?mojtaba malayeriWed, 31 Oct 2018 16:19:03 -0500http://ask.sagemath.org/question/44134/Remove a variable from a polynomial ring k(a,b)[x1,x2,x0] where a,b are parametershttp://ask.sagemath.org/question/38710/remove-a-variable-from-a-polynomial-ring-kabx1x2x0-where-ab-are-parameters/ I am trying to homogenize polynomials using variable `x0` in a polynomial ring `k(a,b)[x1,x2]` defined as follows:
R.<a,b> = PolynomialRing( QQ, order='degrevlex' )
K = FractionField( R )
RK.<x1,x2> = PolynomialRing( K, order='degrevlex' )
After homogenization, I define the new polynomial ring with block order:
RKH.<x1,x2,x0>=PolynomialRing(K,order='degrevlex(2),degrevlex(1)')
Then in my program, I need to dehomogenize my polynomials by setting `x0=1`, and remove the variable `x0` from the polynomial ring. This works fine in a polynomial ring without the parameter fraction field. For example
P.<x,y,z>=PolynomialRing(QQ,order='degrevlex(2),degrevlex(1)')
fp=x^2+x*y+4*z^2
R=P.remove_var(z,order='degrevlex');R
R(fp(z=1)).parent()
Multivariate Polynomial Ring in x, y, z over Rational Field
Multivariate Polynomial Ring in x, y over Rational Field
Multivariate Polynomial Ring in x, y over Rational Field
However, with the fraction field `k(a,b)`, the same method does not work any more:
R.<a,b> = PolynomialRing( QQ, order='degrevlex' )
K = FractionField( R )
RK.<x1,x2> = PolynomialRing( K, order='degrevlex' )
RKH.<x1,x2,x0>=PolynomialRing(K,order='degrevlex(2),degrevlex(1)')
pf=a*x1^2-b*x1*x2+x0^2
RKHn=RKH.remove_var(x0,order='degrevlex')
pfn=pf(x0=1)
RKHn(pfn)
Multivariate Polynomial Ring in x1, x2, x0 over Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field
Error in lines 11-11
TypeError: not a constant polynomial
I didn't copy down the whole error message so it doesn't look so long. Is there a way to fix this? Thank you for your help!KittyLFri, 01 Sep 2017 14:09:49 -0500http://ask.sagemath.org/question/38710/Questions about the parameters in the output of solvehttp://ask.sagemath.org/question/26205/questions-about-the-parameters-in-the-output-of-solve/I am writing a program that, among other things, has to solve many systems of polynomial equations (of degree <= 3) determined by the data entered by the user. Each system of equations consists of 3 equations in 3 variables. Sometimes the equations in a given system are redundant, and therefore the output of solve contains parameters (free variables). Is there any way to know which variables in the output of solve are the parameters (without having to look at the actual output in Sage)?
Here is a simple example.
x,y=var('x,y',domain=RR);
eqn1=x+y==1;eqn2=2*x+2*y==2;
soln=solve([eqn1,eqn2],x,y,solution_dict=True);
soln
The output is
[{x: -r6 + 1, y: r6}]
How do I know which variable is the free variable in this case (without looking at the output)? Is it true that the free variable(s) in the output of solve will always be the "last variable(s)" (in the alphabetical order), `y` in this case? Is there a `is_free_variable` function (similar to the `is_integer` function)? In my program, I need to be able to identify the free variables in the solution of solve, `y` in this case, without looking at the output, and substitute those variables by a few numerical values.
I understand that the `solve` function in Sage uses the corresponding Maxima function. It seems that Sage does not recognize the Maxima function `%rnum_list` (which gives the list of parameters introduced in the solutions by `solve` and `algsys`). Is there a Sage function that does the same as `%rnum_list`?
Thanks,
Aldo
aldoMon, 16 Mar 2015 11:06:26 -0500http://ask.sagemath.org/question/26205/Specifying variables to be included in Hessian calculationhttp://ask.sagemath.org/question/23738/specifying-variables-to-be-included-in-hessian-calculation/I want to calculate the Hessian of a function that has 5 variables and 6 parameters.
I do not want the derivatives taken by the parameters.
Is there a way to separately define parameters and variables in sage?
Alternatively, is there a way to make the Hessian function only use some variables for derivation?ShimiMon, 11 Aug 2014 07:58:23 -0500http://ask.sagemath.org/question/23738/Substituting a particular value for a parameterhttp://ask.sagemath.org/question/11024/substituting-a-particular-value-for-a-parameter/This question is a follow-on to [this one](http://ask.sagemath.org/question/3501/two-questions-about-parameters-in-solutions) I asked earlier. Suppose I have a return value (a list called `sols`) to a `solve` command which includes an extra parameter, like
[2+r1,2-r1,2*r1]
If I want to substitute a value for `r1`, I need to, for example:
var('r1')
[xx.subs(r1=2/3) for xx in sols]
However, if I happen to run the solve command again, the new parameter changes to r2, and then I have to change the above commands to work with r2 instead of r1. And of course if other parameters have been created in the course of my Sage session, the r1 above could be anything.
What I need is some way of both isolating that extra parameter, and substituting for it. One way seems to be something like:
params = [xx.variables()[0] for xx in sols]
[xx.subs_expr(p==2/3) for xx,p in zip(sols,params)]
which works if the extra parameter is listed first in each variable list. The command
solvars = reduce(lambda x,y:union(x,y),[xx.variables() for xx in svals])
produces a list in which the extra parameter is last. So I could use
[xx.subs_expr(solvars[-1]==2/3) for xx in sols]
But none of these particularly automatic, in terms of isolating the extra parameter. They seem to require some extra knowledge of where the parameter is in the variables list.
So what is the best way of doing this, which is robust and automatic?AlasdairTue, 11 Feb 2014 11:38:22 -0600http://ask.sagemath.org/question/11024/solving radical equations with parametershttp://ask.sagemath.org/question/10277/solving-radical-equations-with-parameters/I would like to find the solutions $y$ to this type of equations: $$\left(1+x -\sqrt{(1+x)^2-4y}\right)^2=z$$
with conditions on $x,y,z$ (like $0\lt y\lt x\leq \frac18$ and $0\lt z\lt x^2$).
Using `solve` with the option `to_poly_solve`:
sage: solve((1+x - sqrt((1+x)^2-4*y))^2 == z, y, to_poly_solve=True)
[y == 1/2*x^2 - 1/2*(x + 1)*sqrt(x^2 + 2*x - 4*y + 1) + x - 1/4*z + 1/2]
does not seem to work because $y$ appears on the right side of the solution. I expect to find a solution like
$$y=\frac14\left((1+x)^2-\left(1+x-\sqrt{z}\right)^2\right).$$
I also tried the same after specifying the conditions with `assume()`, without success.nejimbanTue, 25 Jun 2013 03:00:31 -0500http://ask.sagemath.org/question/10277/