Ask Your Question

clon's profile - activity

2021-07-13 17:28:08 +0200 received badge  Famous Question (source)
2020-11-07 20:13:22 +0200 received badge  Notable Question (source)
2020-01-31 01:39:51 +0200 received badge  Popular Question (source)
2019-03-08 08:03:38 +0200 received badge  Good Question (source)
2019-03-06 16:15:40 +0200 received badge  Nice Question (source)
2019-03-06 15:31:14 +0200 received badge  Student (source)
2019-03-06 10:13:19 +0200 commented answer Summation of simbolic variables

Thank you. Changing alpha and area from vectors into functions did the trick. Sorry I can't upvote yet.

2019-03-06 10:11:44 +0200 received badge  Scholar (source)
2019-03-06 10:11:39 +0200 received badge  Editor (source)
2019-03-05 16:46:13 +0200 asked a question Summation of simbolic variables

Hi guys!


I have this function on theta:

$R_{x}(\theta) = R_{tx} + \cos \theta \cdot \left( f_{vp} + \sum_{i=1}^{n} \left(p S_i \sin^2 \alpha_i \right) \right) - \sin \theta \cdot \frac{1}{2} \sum_{i=1}^{n} \left(p S_i \sin 2\alpha_i \right)$


Since I cannot define an n-dimensional vector, I reduced n to 5, and wrote the following code down in SAGE:

var('alpha1, alpha2, alpha3, alpha4, alpha5');    # some angles
var('area1, area2, area3, area4, area5');         # some areas
var('Rtx, Rty');                                  # components of some force
var('fvp');                                       # modulus of yet another force
var('pv');                                        # wind pressure
var('theta');                                     # wind direction
var('i');                                         # variable to iterate over the angles and areas

# this vector contains all the angles
alpha = vector([alpha1, alpha2, alpha3, alpha4, alpha5]);

# this vector contains all the areas
area = vector([area1, area2, area3, area4, area5]);

Upto this point everything seems to go fine.

Then I try to define my function like this:

# The function I am trying to define, depending on the wind direction
Rx(theta) = Rtx + cos(theta) * (fvp + sum(pv * area[i] * sin(alpha[i])^2, i, 1, 5)) - sin(theta) * 1/2 * sum(area[i] * sin(2*alpha[i])^2, i, 1, 5)

And sage complains:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-4889d5aee183> in <module>()
----> 1 __tmp__=var("theta"); Rx = symbolic_expression(Rtx + cos(theta) * (fvp + sum(pv * area[i] * sin(alpha[i])**Integer(2), i, Integer(1), Integer(5))) - sin(theta) * Integer(1)/Integer(2) * sum(area[i] * sin(Integer(2)*alpha[i])**Integer(2), i, Integer(1), Integer(5))).function(theta)

sage/modules/free_module_element.pyx in sage.modules.free_module_element.FreeModuleElement.__getitem__ (/build/sagemath-x4mQwo/sagemath-7.4/sage/src/build/cythonized/sage/modules/free_module_element.c:12935)()

sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__index__ (/build/sagemath-x4mQwo/sagemath-7.4/sage/src/build/cythonized/sage/symbolic/expression.cpp:31916)()

sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._integer_ (/build/sagemath-x4mQwo/sagemath-7.4/sage/src/build/cythonized/sage/symbolic/expression.cpp:8623)()

TypeError: unable to convert i to an integer

Any ideas on what may be happening? And, Is there a way to make it work?

Apparently, my question is similar to: Symbolic function that sums over variable sequence (sorry: my karma is insufficient to post links).

Still, it is different in that I have two vectors of variables and need to define a computation using variables from both vectors. And I was trying to get it done in a different way.

Thank you for your time.

============== EDIT:

This made the trick:

alpha = function("alpha")(i);
area = function("area")(i);
Rx=function("Rx")(theta);
sum1(i) = pv * area(i) * sin(alpha(i)^2)
sum2(i) = area(i) * sin(2*alpha(i))/2

Rx(theta) = Rtx + cos(theta) * (fvp + sum(sum1(i), i, 1, n)) - sin(theta) * sum(sum2(i), i, 1, n)

Thanks to @emmanuel-charpentier

2019-03-05 15:09:24 +0200 commented answer Can I define an n-dimensional matrix?

I have the same issue. I want to compute an expression, similar to: sum{K_i * sen(alpha_i)} where i goes from 1 to n, being n also a variable.

2019-03-05 11:04:49 +0200 commented answer solving a physic problem using sage

Great answer! Sorry I can't upvote it yet. I just created the account, and I need more points.