Code function using Matlab code
显示 更早的评论
Currently, I am working a project with Matlab progrma. I have one problem with the summation variable. This is due lack of experience before. So, could you help me please to code this function in Matlab code: ( ∑_{ i=1}^{n} (f(x_{i})-y_{i} )^2). Look forward to hearing from you soon.
采纳的回答
更多回答(1 个)
Walter Roberson
2015-6-7
Assuming that your function f is vectorizable, and assuming that x_ and y_ are of length n, then
sum((f(x_)-y_).^2)
if they are a different length then
sum((f(x_(1:n))-y_(1:n)).^2)
If your f is not vectorizable, but (for simplicity) assuming that x_ and y_ are the right length,
sum( (arrayfun(@f, x_) - y_).^2 )
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!