Skip to main content
13-Aquamarine
January 2, 2019
Solved

Indexing functions

  • January 2, 2019
  • 3 replies
  • 1861 views

First of all a happy prosperous and especially healthy 2019 to all! I have apparently a misunderstanding when to use indexing versus vectorisation. In the attached worksheet indexing works but vectorisation doesn't. Could someone help me out with this because I seem to be lost.

Best regards, Filip

Best answer by Werner_E

When doing calculations where you later want to fill in vectors of data I would strongly recommend to set up all those calculations as functions dealing with scalars only and later call those functions vectorized with the data vectors as arguments.

See attached worksheet.

 

3 replies

21-Topaz II
January 2, 2019

Hi,

 

In the first instance of indexing, f(p,i) returns a single value at any point p and thus can be numerically integrated with respect to "p".


In the second instance of vectorisation, f(p) returns a vector as the result. "p" as an input can be either a single value or a vector of similar size to PA50. It is not possible to numerically integrate a function that returns a vector at every point. The integration thus fails.

 

Cheers

Terry

 

 

Werner_E25-Diamond IAnswer
25-Diamond I
January 2, 2019

When doing calculations where you later want to fill in vectors of data I would strongly recommend to set up all those calculations as functions dealing with scalars only and later call those functions vectorized with the data vectors as arguments.

See attached worksheet.

 

FDS13-AquamarineAuthor
13-Aquamarine
January 2, 2019

Terry, thank you so much for the clarification as this explains the why.

Werner, thank you for your additional hint. It is indeed a much clearer way to do it the way you propose. I will try to use this not only for this worksheet but also for future ones.

All the best, Filip