Info

此问题已关闭。 请重新打开它进行编辑或回答。

Problem with function handling

2 次查看(过去 30 天)
eddie
eddie 2018-7-18
关闭: MATLAB Answer Bot 2021-8-20
Hi everyone, please if anyone can help me with this, I would be really grateful. I'm trying doing this:
fun=@(z) beta.*(abs(1-z(1).*(1-x{1}/y{1})).*abs(1-z(2).*(1-x{2}/y{2})).*...
abs(1-z(3).*(1-x{3}/y{3})).*abs(1-z(4).*(1-x{4}/y{4})))-alpha;
where:
for ii=1:size(X,1)
for i=1:m
x{i}(ii)=sum(X{ii}(n(i,1):n(i,2)));
end
end
for i=1:m
y{i}=sum(Y(n(i,1):n(i,2)));
end
There is a possibility to simplify the function "fun" (as a product) by including this, for example, into a for loop?
I'm trying using this:
for i=1:m
fun=@(z) beta.*prod(abs(1-z(i).*(1-x{i}/y{i})));
end
but it doesn't work. What should I do?
Thanks in advance
  1 个评论
Walter Roberson
Walter Roberson 2018-7-20
Please do not close questions that have an answer.

回答(1 个)

Guillaume
Guillaume 2018-7-18
I'm really not clear what are variables (inputs) to your function and what are constants. Why is your anonymous function just a function of z but not also x and y? Also, why are x and y cell arrays?
As far as I can tell your equation is
result = beta * prod(1 - z .* (1 - x./y)) - alpha
assuming that z, x, and y are all vectors or matrices of the same size.

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by