I want to code this function in matlab ( ∑_{ i=1}^{n} f(x_{i})-y_{i} ), x_{i}=(x_{1},x_{2},...,x_{n}) and y_{i}=(y_{1},y_{2},...y_{n}). So, how can I write the code. Is there anyone who can help me? Thanks in advance.
Best regars, John

댓글 수: 2

James Tursa
James Tursa 2015년 6월 7일
Do you know how to write a loop? Do you know how to use indexes with variables? Do you know how to call a function? What is f? What have you done so far?
John Gebre
John Gebre 2015년 6월 7일
Thank you for your interest to help me. It is clear the loop and calling a function. But, it is not clear for me how to use index with variables? So, focus on this point.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 7일

0 개 추천

for K = 1 : 5
Z(K) = X(K) - Y(K);
end

댓글 수: 2

John Gebre
John Gebre 2015년 6월 7일
편집: John Gebre 2015년 6월 7일
Thank for the index. But could you help me please how to code this function: ( ∑_{ i=1}^{n} f(x_{i})-y_{i} ). Look forward to hear from you soon.
It's just trivial renaming of the variables, and putting the x-y difference into f().
for i = 1 : n
fi(i) = f(x(i) - y(i));
end
theFinalSum = sum(fi);
Where f is your function. Or you could do this:
theSum = 0;
for i = 1 : n
theSum = theSum + f(x(i) - y(i));
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2015년 6월 7일

댓글:

2015년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by