Clear Filters
Clear Filters

Error in fsolve (line 408) trustnleqn​(funfcn,x,​verbosity,​gradflag,o​ptions,def​aultopt,f,​JAC,...

2 views (last 30 days)
Error codes:
Check for missing argument or incorrect argument data type in call to function 'trustnleqn'.
Error in fsolve (line 408)
trustnleqn(funfcn,x,verbosity,gradflag,options,defaultopt,f,JAC,...
Error in NET1_2020main (line 28)
x=fsolve('NET1_2020func',x0,opt,q_s(i,1),tau1,sigma,e2,e1,alpha_c,alpha_1,alpha_2,cp,mw,Tw_in,T_sky(1,1),T0(1,1));
Main code and function:
format short
x0=[0 0 0 0 270 280];
opt=optimset('fsolve');
q_s=[0 30;0 80;0 130;40 200;80 280; 110 380;140 500;170 610;100 550;70 500;50 450;0 330;0 220;0 110;0 60;0 30];
tau1=0.85;
sigma=5.665*10^-8; %W/m^2*K^4
e1=0.05;
e2=0.85;
cp=4200; %J/kg*K
alpha_c=10; %W/(m^2*K)
alpha_1=0.05;
alpha_2=0.85;
Tw_in=333.15; %K
T_sky=[247 268]; %K
T0=[270 285]; %K
Q_1=0;
Q_2=0;
mw=0.05; %calculated /m2
%Day1
for i=4:(length(q_s(:,1))-5);
opt=optimset('fsolve');
x=fsolve('NET1_2020func',x0,opt,q_s(i,1),tau1,sigma,e2,e1,alpha_c,alpha_1,alpha_2,cp,mw,Tw_in,T_sky(1,1),T0(1,1));
T2=x(6);
Tw_out=2*T2-Tw_in;
q_w(i,1)=5*cp*mw*(Tw_out-Tw_in);
Q_1=Q_1+q_w(1,1);
end
%Day2
for i=1:length(q_s(:,2));
opt=optimset('fsolve');
x=fsolve('NET1_2020func',x0,opt,q_s(i,2),tau1,sigma,e2,e1,alpha_c,alpha_1,alpha_2,cp,mw,Tw_in,T_sky(1,2),T0(1,2));
T2=x(6);
Tw_out=2*T2-Tw_in;
q_w(i,2)=5*cp*mw*(Tw_out-Tw_in);
Q_2=Q_2+q_w(1,2);
end
Q_tot=Q_1+Q_2;
print=['Total energy recovered during both days: ', num2str(Q_tot),' Wh'];
disp(print)
function f=NET1_2020func(x,q_s,tau1,sigma,e2,e1,alpha_c,alpha_1,alpha_2,cp,mw,Tw_in,T_sky,T0)
q1_in=x(1);
q1_out=x(2);
q2_in=x(3);
q2_out=x(4);
T1=x(5);
T2=x(6);
q12=q1_out-q1_in;
q_conv1=alpha_c*(T1-T0);
q_rad1=sigma*e1*(T1^4-T_sky^4);
Tw_out=2*T2-Tw_in;
f(1)=q1_out+tau1*q_s-q2_in;
f(2)=sigma*e2*T2^4+(1-e2)*q2_in-q2_out;
f(3)=q2_out-q1_in;
f(4)=sigma*e1*T1^4+(1-e1)*q1_in-q1_out
f(5)=q_conv1+q_rad1+q12-alpha_1*q_s;
f(6)=mw*cp*Tw_out-mw*cp*Tw_in-q12-tau1*alpha_2*q_s;
end

Accepted Answer

Ameer Hamza
Ameer Hamza on 30 Mar 2020
Edited: Ameer Hamza on 30 Mar 2020
fsolve accepts function handle. Change the line like this
x=fsolve(@NET1_2020func,x0,opt,q_s(i,1),tau1,sigma,e2,e1,alpha_c,alpha_1,alpha_2,cp,mw,Tw_in,T_sky(1,1),T0(1,1));
%^ write like this instead of character array
Do it for both calls to fsolve.
  8 Comments
Oskari Lehtinen
Oskari Lehtinen on 30 Mar 2020
Thank you! When i outputted "which fsolve", I realised i had it on the wrong place. Now I got the same answer that you put on the attached file. Problem solved:)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!