Skip to main content
12-Amethyst
March 26, 2025
Solved

Repeat a function and save the results in a vector

  • March 26, 2025
  • 2 replies
  • 802 views

Hi

I have tried to create a program that calculates a function for each value in the vector, but the result is not being saved for each loop. What am I doing wrong? Thanks for your help. 

 

ksk_10594232_0-1742994035931.png

 

Best answer by rgunwaldsen

You just need to change "For" statement to make "i" a real range (not just 3),.

 

rgunwaldsen_0-1742996918043.png

 

2 replies

15-Moonstone
March 26, 2025

You just need to change "For" statement to make "i" a real range (not just 3),.

 

rgunwaldsen_0-1742996918043.png

 

12-Amethyst
March 26, 2025

Thank you!

25-Diamond I
March 26, 2025

You could avoid any programming and loops

Werner_E_0-1743007250531.png

Vectorization (the arrow over the expression) is not mandatory here but I  it good style to use it whenever a scalar calculation is applied to the elements of a vector. In case of your example we sure can see it as a vector calculation and omit vectorisation.