Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How to pass anonymous handle in a for loop?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 5 Jun. 2018
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 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!