フィルターのクリア

How to avoid dividing by zero in this function?

35 ビュー (過去 30 日間)
Matthew Palermo
Matthew Palermo 2023 年 11 月 20 日
コメント済み: Walter Roberson 2023 年 11 月 30 日
I fixed a previous issue of constant values and now the challenge is figuring out how to avoid dividing by zero. I figured that simply advacing the time steps would help, but it did not. Any help is much appreciated.
%```
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 = ones(lengthx);
% td = ones(lengtht);
for ix=1:lengthx % Begin time loop
xd_ix=x_til(ix); % Set current time
for it=1:lengtht % Begin space loop
td_it=t_til(it); % Set current space
if td_it == 0 % For time t=0 condition
T_til1(it+1,ix+1)=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```
  2 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 11 月 20 日
I don't see any issue in the posted code
if td_it is >0 there should be no division by zero in T_til1(ix,it)=erfc(xd_ix/sqrt(4*td_it))
Walter Roberson
Walter Roberson 2023 年 11 月 30 日
You should probably be storing into the same location in both branches.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by