Jump to content



Featured Articles

Check out the latest featured articles.

File Library

Check out the latest downloads available in the File Library.

New Article

Product Viscosity vs. Shear

Featured File

Vertical Tank Selection

New Blog Entry

Low Flow in Pipes- posted in Ankur's blog

How To Solve For Loop Matlab When Nan Is Occur


This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic
Share this topic:
| More

#1 i am lido

i am lido

    Brand New Member

  • Members
  • 8 posts

Posted 23 March 2016 - 09:18 PM

Dear all

 

I face a problem with for loop in matlab. My equation is 

Jw(i) = p1 - p2*Jw(i)/(1+B/Jw(i))-P

 

when I use for loop to step size Jw(i), the output show NaN because this term (B/Jw(i)) . This Jw is in divided term.

When I rearrange this equation, this term is still appear.

 

How to solve this problem? Please help me.

 

Best regards,

Lida



#2 serra

serra

    Gold Member

  • Members
  • 311 posts

Posted 24 March 2016 - 03:05 AM

normally Matlab manages well (and reports) floating point errors,

some possible causes

|Jw(i)| ~ 0

index i outside range

but there may be others



#3 Pilesar

Pilesar

    Gold Member

  • Members
  • 1,555 posts

Posted 24 March 2016 - 11:16 AM

Test for Jw(i)=0 in your algorithm inside your loop. Then take steps to avoid dividing by zero.



#4 Francisco Angel

Francisco Angel

    Gold Member

  • Members
  • 88 posts

Posted 24 March 2016 - 01:11 PM

You could try with the isnan function:

 

http://www.mathworks.../ref/isnan.html

 

To detect the cases, and be capable of completing the loop.

 

Best regards.






Similar Topics