Modified code to fix Tenv(i) to pass to the funh.m
________________________________________
clear clc Ta=zeros(1,25); t=1; Ta(1)=16+273; Te=[9 12 10 10 18 18 11 11 11 11 12 16 16 18 18 20 20 15 15 13 13 12 12 10 9 9 12 10 10 10 10 11 11 11 11 12 16 16 18 18 20 20 15 15 13 13 12 12 10 9 9 12 10 10 10 10 11 11 11 11 12 16 16 18 18 20 20 15 15 13 13 12 12 10 9 9 12 10 10 10 10 11 11 11 11 12 16 16 18 18 20 20 15 15 13 13 12 12 10 9]'; P=ones(1,25); x0(2)=293; x0(1)=6; for i=2:100 % fun = @funh; Tain=Ta(i-1); Tenv(i)=Te(i)+273; options = optimoptions('fsolve','Display','iter') [xopt,Fval,exitflag] = fsolve(@(x)funh(x,Tain,Tenv(i)),x0,options) Ta(i) = xopt(2); % Tain=xopt(2); xsav(i,:) = xopt; end i=1:1:100; plot(i,xsav(:,1),i,xsav(:,2));
------------------- Now I am getting the Ta as almost constant for all iterations while the xsav(1) fluctuated to negative and positive values. The expected values should be positive real for xsav(1) while xsav(2) should give more fluctuation. @star strider I am not familiar with patternsearch and neither the Matlab help recognizes this.