Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to pass anonymous handle in a for loop?
1 回表示 (過去 30 日間)
古いコメントを表示
function [o] = testScript(x)
input1 = [2,3,4,5,6,7,8];
input2 = [3,9,1.3,4,0.9,1.1,1.2];
output = [2.5071,11.5204,1.3981,6.0947,1.2437,1.7801,2.2177];
Re = input1.*(input2.^2);
Pr = input2./input1;
Var3 = input1+input2;
Var4 = input1.*input2;
for i = 1:7
syms x(i)
h(i) = @(x) (x(1)*(Re(i)^x(2))*(Pr(i)^x(3)));
k(i) = @(x) x(4)*(Re(i)^x(5))*(Var3(i)^x(6))*(Var4(i)^x(7));
o(i) = output(i) - h(x)(i) - k(x)(i);
end
end
I am trying to fsolve to calculate the value of x,but it gives me error - looks like I am not using the right command to pass handles to the function
as % fun = @testScript
% x0 = [ 0.2,0.3,0.4,0.5,0.15,0.2,0.3];
% x = fsolve(fun,x0)
0 件のコメント
回答 (1 件)
Walter Roberson
2018 年 6 月 5 日
You cannot store function handles indexed with () brackets.
for i = 1:7
syms x(i)
h{i} = @(x) (x(1)*(Re(i)^x(2))*(Pr(i)^x(3)));
k{i} = @(x) x(4)*(Re(i)^x(5))*(Var3(i)^x(6))*(Var4(i)^x(7));
o(i) = output(i) - h{i}(x) - k{i}(x);
end
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!