Triple Summation in Matlab

Following Formula uses triple index summation.
How can I achieve this in matlab. All of the terms being summed are row vectors ( coefficients of polynomial ) except f(xi , yj , zk) is a row vector of numbers.

5 Comments

If Lp,i Lq,j and Lr,k are row vectors, then what do the variables x y and z denote here? Are x, y, and z vectors or scalars? Can you show how these terms are defined?
If x and y and z are row vectors, then:
if is a scalar, then scalar times row vector x times scalar would be row vector, and then multiplying by y would be row vector times row vector, which would be understood as algebraic matrix multiplication and would fail because the size of the second dimension (length of the first row vector) would not match the first dimension (1) of the second row vector.
I think you have size problems in your definitions.
f(xi ,yj ,zk) is a row vector of function values evaluated from x =[1 2 3] , y = [4 5 6] and z = [7 8 9]
size of f(xi ,yj ,zk) is equal to (size of x) * (size of y) * (size of z)
x ,y ,z contain only numeric values whereas L(x), L(y) and L(z) are Lagrange Coefficients i.e., L(x) contains coefficients of Lagrange Polynomial. Lagrange Coefficients are calculated from following code.
w=length(x);
l=w-1;
L=zeros(w,w);
for k=1:l+1
A=1;
for j=1:l+1
if k~=j
A=conv(A,poly(x(j)))/(x(k)-x(j));
end
end
L(k,:)=A;
end
L
L is a w*w matrix containg all of the Lagrange coefficeints. For example, it may be
L = 2×2
-100.0000 6.0000
100.0000 -5.0000
1st row represents ( -100x + 6 ) whereas 2nd row represents ( 100x - 5x ).
If L was a 3x3 matrix then all of the rows represent ( ax^2 + bx +c ) polynomials.
Now coming to the value of p q & r
Consider following three vectors
x = [x0 x1 x2]
y = [y0 y1 y2]
z = [z0 z1 z2]
in this case p=2, q=2, r=2
And if
x = [x0 x1 x2 x3]
y = [y0 y1 y2 y3]
z = [z0 z1 z2 z3]
then p=3, q=3, r=3
We can imply that in summation, we wil be having 3 terms. So, it is simply equal to
p=length(x)
q=length(y)
r=length(z)
So, we can use Summation from 1 to length(x or any vector being used).
For Lp,i(x), consider length(x) = 3 then p=3 so, L3,i(x). In loop first value of i will be 1, then L3,1(x). This simply means that from lagrange coefficients matrix we have to use first row which is a polynomial. Therefore, L3,2(x) means 2nd row and similarly L3,3(x) means 3rd row.
From this explaination, I hope you can get the whole picture of what I wanted to ask.
size of f(xi ,yj ,zk) is equal to (size of x) * (size of y) * (size of z)
That means that given scalar xi, yj, zk, then f(xi, yj, zk) is a 3 dimensional array. A 3 dimensional array is not a "row vector"
p=length(x)
That disagrees with p=2 for x = [x0 x1 x2] . It looks to me as if p is the degree of the polynomial implied by x, which would be length(x)-1
This simply means that from lagrange coefficients matrix we have to use first row which is a polynomial.
As in sum(L3(1,:) .* x.^(length(x)-1:-1:0)) ?
I calculated all of the possible combinations of f(xi ,yj ,zk) by using following code
syms x y z
f = @(x,y,z)x.*y+z; % Insert your function
x = [ 0.05 0.06 ];
y = [ 1.23 1.41 ];
z = [ 0.1 0.2];
[XX,YY,ZZ] = meshgrid(x,y,z); % Create all possible combinations
Q = f(XX(1:end),YY(1:end),ZZ(1:end))
It gives a 1x8 matrix containg all of the function values. These are just numbers.
For value of p, I'll give an example
consider following matrix
x = [x0 x1 x2 x3]
As you can see last entry is x3, so p=3. Similarly, if last entery is x2 or x4, p will be 2 and 4 respectively.
Now consider
x = [x1 x2 x3 x4]
we will sum from 1 to 4, thereby p=4 whereas in above example p=3 but we are going to sum from 0 to 3, both of which are same i.e., number of terms which are being summed are 4.
For Lagrange coefficients, I think we can use conv to multiply them beacause these are Lagrange Polynomials.

Sign in to comment.

Answers (0)

Categories

Asked:

on 28 Jun 2020

Edited:

on 29 Jun 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!