Info
This question is closed. Reopen it to edit or answer.
Summation of two vectors over a range
2 views (last 30 days)
Show older comments
I have to write a code in Matlab for adding the following two vectors
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196575/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196576/image.png)
The elements corresponding to
and
are the boundary elements. So
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196577/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196578/image.png)
if the values of the vector are chosen as
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196579/image.png)
and with boundary conditions
at both ends, I wrote the code, but there's a dimensions mis-match later on. So I was
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196580/image.png)
thinking maybe I wrote something wrong in the code for the addition of the two vectors above.
The code I wrote to implement this vector addition is
maxm=5;
X = [-4, -6, -13, -9, -16]
BConleft=X*exp(-3*i);
BConright=X*exp(-3*i);
sumneighborsX = [X(2)+BConleft,diff(X,2)+2*X(2:maxm-1),X(maxm-1)+BConright]
4 Comments
Irfan ahmed
on 25 Nov 2018
The values
are taken as [-1,-2,-3,-4,-10,-5,-6] to create X by summations
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196586/image.png)
Answers (1)
Image Analyst
on 26 Nov 2018
Looks like you're trying to do a convolution:
sumOfNeighborsX = conv(X, [1,0,1], 'full');
Are you?
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!