Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEWBIE function with sum of multiple parameters

Status
Not open for further replies.

grizos

Electrical
Nov 30, 2005
2
I am very new to Matlab and such programms generally. I want to implement such a function:

y = sum(Xi) where i = 1 to 20
Xi are unknown parameters. how can I do this to Matlab?

Of course i can do: y= x1 + x2 + x3... but it's ridiculous.

My final target is to minimize such a function with genetical algorithms. Of course this is not the real function. It's simply demonstrates what I need to learn. Thank you all
 
Replies continue below

Recommended for you

I'm not sure that I totally understand your issue. It seems that you have the answer in your question, which is why I say this. If you have an array i defined as "i = [1,2,3,4,5,6,7,8,9,10]" and you use the function "y = sum(i)", Matlab will provide you the answer y = 55. In other words, the function already exists. Perhaps I'm not interpreting your question correctly.
 
Well I found a solution. Sorry for not syntaxing my question right. With the solution you will understand my question too :)

r = func(x)

r=0;

for i=0:20
r= r+ sum(x(i));
end

so func is a function with 20 unknown variables x(1) ... x(20)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor