How to solve warning: division by zero

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to solve warning: division by zero

이태훈
Hi all 
I use this code for my work, Whenever I run this, I get this:
 warning: division by zero
warning: called from
    EulerExplict at line 25 column 11
Can you help me to solve this problem?  


Code:
% Solve ODE-IVP using Euler's Explict Method
  
   t0 = 0 ;
   y0 = 9.8;
   tEnd = 5;
   h= 0.1;
   N = (tEnd.-t0)./(h);
   D=1.1;
   r=0.0984;
   ka=3;
   z=10;
   umax=0.08;
   km=3;
   I0=1;
   
   
   %%Initializing Solution
   
   T = [t0:h:tEnd]';
   Y = [N+1,1]';
   y(1) = y0;
   
   %% Solving using Euler's Explicit Method 
   for i= 1:N
       fi = 20.*2.717.^((umax.*(I0.*2.717.^(((-3).*(Y(i)).*(z))./(I0.*2.717.^((-3).*(Y(i)).*(z))).+km))-D).*T(i));
       Y(i+1) = Y(i).+(h.*fi);
     
     end
       
   
   disp(Y)
   plot(T,Y);
 


Reply | Threaded
Open this post in threaded view
|

Re: How to solve warning: division by zero

mmuetzel
Am 21. April 2020 um 17:13 Uhr schrieb "이태훈":
> Hi all 
> I use this code for my work, Whenever I run this, I get this:
>  warning: division by zero
>  warning: called from
>     EulerExplict at line 25 column 11
> Can you help me to solve this problem?  
>  
>  
> Code:
[snip]
>    t0 = 0 ;
[snip]
>    T = [t0:h:tEnd]';
[snip]
>    for i= 1:N
>        fi = 20.*2.717.^((umax.*(I0.*2.717.^(((-3).*(Y(i)).*(z))./(I0.*2.717.^((-3).*(Y(i)).*(z))).+km))-D).*T(i));
>        Y(i+1) = Y(i).+(h.*fi);
>      
>      end

T(1) is t0 which is 0. So you are dividing by zero. Hence the warning.

If you want to suppress the warning, have a look at the documentation for "warning":
doc warning

Query the id of the last warning with
[~, id] = lastwarn ()

HTH
Markus