FUN must be a function, a valid character vector expression, or an inline function object. | fzero
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
function T = FA(y)
for i = 1:length(y)
if y(i) >= 12.5
N1(i)= 0
N2(i)= 8
N3(i)= 9
N4(i)=3.76*y(i)
N5(i)= y(i)-12.5
else
N1(i)= 2*(12.5 -y(i))
N2(i)= 2*(y(i) - 8.5)
N3(i)= 0
N4(i)=3.76*y(i)
N5(i)= 0
end
f{i}=@(T)-5078905.27 + N1(i)*(297334.224)+ N1(i)*((299180+37.85*(T)+(-4571.9)*log(T))-294170.430054)+N2(i)*((56835+66.27*(T)+(-11634)*log(T))-24557.403501)+N3(i)*((88923+49.36*(T)+(-7940.8)*log(T))-69574.657860)+N4(i)*((31317+37.46*(T)+(-4559.3)*log(T))-26135.539906)+N5(i)*((43388+42.27*(T)+(-6635.4)*log(T))-27886.197583)
fzero(f,2500)
end
I know that if I change f{i} to f(i) I'll be able to run the script and input whatever values I want. However, I need this script tor work in conjuction with this one
clc; clear; close all;
r = .7:.1:2.0;
y = 12.5*r
T = FA2(y);
I eventually want to plot the r values vs. the T values (fzero outputs). If I change f{i} to f(i) I get a different error code on the second script, "Nonscalar arrays of function handles are not allowed; use cell arrays instead."
What do I need to do to make these work together? Thank you
1 Kommentar
Stephen23
am 16 Okt. 2018
"I know that if I change f{i} to f(i) I'll be able to run the script and input whatever values I want."
No, actually you will get an error (because function handles cannot be put into an array).
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!