Symbolic Sum to find a general expression for arbitrary n terms and arbitrary variable definitions
Mostra commenti meno recenti
Hello, I have a need to add some terms defined using an index for the index running from 1 to and arbitrary number n.
I have equations similar to (actual equations are too long but the problem is the same):


⋮

where
is an arbitrary number associated with 
is an arbitrary number associated with 
Goal:
I wish to find the average of these terms running from 
syms x m
e = x + p_{m} % I want to know how to define this p_{m}
symsum(e, m, 1, n)
But I have the following question:
Question:
1) How do I define arbitrary symbolic variables
's for each equation. So that when I get the final sum of all the symbolic variables from 1 to n it will contain
.
's for each equation. So that when I get the final sum of all the symbolic variables from 1 to n it will contain
.Please provide example code.
2 Commenti
atharva aalok
il 24 Set 2022
atharva aalok
il 24 Set 2022
Modificato: atharva aalok
il 24 Set 2022
Risposte (1)
Walter Roberson
il 24 Set 2022
You cannot do that in MATLAB for symbolic limits.
For specific limit, n being a given positive integer, then you would not use symsum for this purpose. Instead,
n = a positive integer
syms a [1 n]
syms x [1 n]
y = sum(a.*x)
That is, you create vectors or arrays in which each entry is a scalar symbol. You then do vectorized operations, producing a vector or array of definite terms. You then sum() the definite terms.
symsum is not primarily for creating a sum of definite terms: symsum is primarily for trying to find closed formulas for indefinite or infinite summations.
Under no circumstances can you use a symbolic variable as an array index.
4 Commenti
atharva aalok
il 24 Set 2022
Modificato: atharva aalok
il 24 Set 2022
Walter Roberson
il 24 Set 2022
e = x + sym(sprintf('p%s', char(k)))
which would give you the definite term
e = x + pk
if you were to symsum(e, k, 1, n) then the result would be n*x + n*pk
Walter Roberson
il 24 Set 2022
You need to understand that the parameters to functions are fully evaluated before the function ever sees them
Walter Roberson
il 24 Set 2022
So what would be passed to the sprintf is not going to be the "current" value of k for a series of values 1 to n: what is going to be passed to sprintf is the unresolved symbol k. So the sprintf would be invoked once to create literal 'pk' which gets you symbol pk and x + pk would get passed to symsum where that pk has no more connection to k than x does.
symsum will then internally subs(EXPRESSION, k, n) and subs(EXPRESSION, k, n+1) and possibly other terms and will work with those to try to come up with a closed formula. The difference would be 0 because x+pk contains no reference to k so symsum will predict the formula (x+pk) * (n-1+1). symsum will not add up the terms one by one.
Categorie
Scopri di più su Calculus in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

