using summation within a function
2 次查看(过去 30 天)
显示 更早的评论
I'm trying to compute something like this:
x=1:100
n=1:10
y=sum(x+n) (or any other f(x))
This only works if n and x have the same dimension as matrix, but what I'm after is to use to derive y =f(x) but so far I had no luck any help is wellcome
thanks
1 个评论
Walter Roberson
2016-3-13
In a case like that, what size would you want y to come out as, and what values?
回答(1 个)
Dave Behera
2016-3-24
The x + n part will only work if they are the same dimension. Can you please describe in detail what you are referring to as 'derive y =f(x)'?
2 个评论
Sa'adatu Abubakar
2021-7-10
I want to use the summation function inside the newtonRaphson algorithm, how can I express it I used symsum(f,k,a,b) but it dosnt work. Do I need to use for loop?
Walter Roberson
2021-7-11
sum(arrayfun(@f, a:b))
If f returns a non-scalar value then you might need
temp = arrayfun(@f, a:b, 'uniform', 0);
nd = ndims(temp{1});
y = sum(cat(nd+1, temp{:}),nd+1);
另请参阅
类别
在 Help Center 和 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!