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!