Matlab  Summation two variables
Printed From: ProjectsQA
Category: Projects Forum
Forum Name: MATLAB Projects
Forum Discription: Projects and discussion on various areas of Matlab like Computer Vision, Image Processing, Signal Processing, Wireless Communication, Deep Learning, Data Analytics, Robotics, Control Systems
URL: http://projectsqa.com/forum_posts.asp?TID=2491
Printed Date: 22Nov2019 at 6:15pm
Topic: Matlab  Summation two variables
Posted By: skumar
Subject: Matlab  Summation two variables
Date Posted: 06Feb2018 at 7:08pm
I'm fairly new to Matlab programming and am having difficulty expressing this equation on Matlab:
g(j)= ∑ (y(n)*x(nj))
where the sum is from n = 8 to 10 for example.
The end result I want is a discrete function like:
g(j) = y(8)*x(8j) + y(9)*x(9j) + y(10)*x(10j)
which I'll ultimately evaluate with a for loop at say j = 6 and 7.
x(n) and y(n) are defined from n=0,...,1000 by the way.
Anybody have any tips on how to accomplish this. This may be simple, but for some reason is giving me problems.

Replies:
Posted By: siva
Date Posted: 06Feb2018 at 7:10pm
Kumar,
If I got you wrong, please let me know.
Being new to MATLAB, you may not know some critical points. If you're not working with Symbolic concept, MATLAB works with only numbers (i.e., matrices). So, I think choosing j=6,7 does not make sense. I'm ok with the creation of the function g, I think you're trying to convolve these two signals but why do you want it to take the values 6 and 7 at the same time? Let's say there is no mistake. The requested form is like shown below;
code:
1. x=1:2:2000;% linspace command could be used like x=linspace(0,2000,1000);
2. y=0:2:1999;% linspace command could be used like y=linspace(1,1999,1000);
3. g=[];
4. sum6=0;
5. sum7=0;
6. j=6;
7. for i=8:10
8. g(j)=y(i)*x(ij);
9. sum6=sum6+g(j);
10. end
11. j=7;
12. for i=8:10
13. g(j)=y(i)*x(ij);
14. sum7=sum7+g(j);
15. end
16. fprintf('g(6) is equal to %d\n', sum6)
17. fprintf('g(7) is equal to %d\n', sum7)
This code may be reorganized but I prepared the code like this because you need to learn MATLAB step by step. If you need to ask sth, please don't hesitate.

Posted By: PrashanthS
Date Posted: 06Feb2018 at 7:11pm
If you're interested in learning how to actually code this, the above is a good suggestion.
But if you just want the result, try the conv() function (or any of the assortment of fir() type functions)

