Function may not have a root
Show older comments
I am getting this eror with this code and associated functions:
Exiting fzero: aborting search for an interval containing a sign change
because no sign change is detected during search.
Function may not have a root.
Here is the code and functions:
close all
clear all
clc
% %FOR A = 3
%
x_til = linspace(0,1,10);
dt = 0.1;
tmax = 1;
t_til = linspace(dt,tmax,10);
nt = length(t_til);
nx = length(x_til);
x0 = [0.0000001 1];
tp1 = ones(nt);
tp2 = zeros(nt);
for A = 3 %finding tp actual
for jx = 1:nx
Tfun1 = @(tp) fX10B1T0(x_til(jx),tp);
Tfun1A = @(tp) (1*(10^(-A))) - Tfun1(tp);
tp1(jx) = fzero(Tfun1A,x0(1));
end
for jx = 1:nx
Tfun2 = @(tp) fX11B10T0(x_til(jx),tp,A);
Tfun2A = @(tp) (1*(10^(-A))) - Tfun2(tp);
tp2(jx) = fzero(Tfun2A,x0(1));
end
end
for ix = 1:nx
for it = 1:nt
TX10B1T0 = fX10B1T0(x_til,t_til);
end
plot (x_til, TX10B1T0(ix,:));
end
function [T_til1] = fX10B1T0 (x_til, t_til)
lengthx=length(x_til);
lengtht=length(t_til);
T_til1=zeros(lengthx,lengtht); % Preallocating Arrays for speed
xd = zeros(lengthx);
td = zeros(lengtht);
for ix=1:lengthx % Begin time loop
xd_ix=xd(ix); % Set current time
for it=1:lengtht % Begin space loop
td_it=td(it); % Set current space
if td_it == 0 % For time t=0 condition
T_til1(it,ix)=0; % Set inital temperature
else
% Solution at any time
T_til1(ix,it)=erfc(xd_ix/sqrt(4*td_it));
end % if td_it
end % for ix
end % for it
end % function
function [T_til2] = fX11B10T0 (t_til, x_til,A)
lengthx=length(x_til);
lengtht=length(t_til);
T_til2=zeros(lengtht,lengthx); % Preallocating Arrays for speed
for it=1:lengtht % Begin time loop
td_it=t_til(it); % Set current time
for ix=1:lengthx % Begin space loop
xd_ix=x_til(ix); % Set current space
td_dev1=(1/(10*A))*(2-xd_ix)^2; % First deviation time
td_dev2=(1/(10*A))*(2+xd_ix)^2; % Second deviation time
if td_it == 0 % For time t=0 condition
T_til2(it,ix)=0; % Set inital temperature
elseif td_it <= td_dev1 % Solution for first small times:
T_til2(it,ix)=erfc(xd_ix/sqrt(4*td_it));
elseif td_it > td_dev1 && td_it <= td_dev2 % Solution for second small times:
T_til2(it,ix)=erfc(xd_ix/sqrt(4*td_it))-erfc((2-xd_ix)/sqrt(4*td_it));
else
m_max=ceil(sqrt(A*log(10)/(td_it*pi^2))); % Set max. No. terms
% Start X11B10T0 case for large times:
T_til2(it,ix)=1-xd_ix; % steady-state temperature solution
for m=1:m_max % Continue X11B10T0 case for large times
% Series solutions:
betam=m*pi; % Define eigenvalues
T_til2(it,ix)=T_til2(it,ix)-2*exp(-betam^2*td_it)*sin(betam*xd_ix)/betam;
end % for m
end % if td_it
if xd_ix == 1 % For location x=1 condition
T_til2(it,ix)=0; % Set x=1 boundary temperature
end % if xd_ix
end % for ix
end % for it
end % function
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!