Skip to main content
8-Gravel
June 17, 2022
Solved

Loop to plot

  • June 17, 2022
  • 1 reply
  • 1830 views

Can I loop the function to solve and plot the equation in prime? 

Best answer by Werner_E

Something like this?

Werner_E_2-1655479600043.png

You have to use matrix indices when defining sigma.0 and sigma.1 and add the unit,  even if the value is zero.

(vectorization isn't necessary here as but a good habit to explicitly apply)

 

Of course the same effect could be achieved easier

Werner_E_1-1655479564611.png

 

 

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
June 17, 2022

Something like this?

Werner_E_2-1655479600043.png

You have to use matrix indices when defining sigma.0 and sigma.1 and add the unit,  even if the value is zero.

(vectorization isn't necessary here as but a good habit to explicitly apply)

 

Of course the same effect could be achieved easier

Werner_E_1-1655479564611.png

 

 

8-Gravel
June 17, 2022

Is there any specific reason why I am only getting two values for returning sigma

JB_10220769_0-1655482210353.png

 

25-Diamond I
June 17, 2022

As an afterthought I overlooked that you can/should delete the last single sigma_i in the for loop as it has no effect. There is also no need for "j" which is never used.

 


@JB_10220769 wrote:

Is there any specific reason why I am only getting two values for returning sigma

 


Yes, its because you defined a FUNCTION epsilon(..), not a simple variable epsilon as i did. This function is never called and so sigma consists of the two values you manually assigned.

Note that nothing you change inside a program can change anything on worksheet level, even if the variable has the very same name (like sigma in your case). Only way to change a worksheet variable with a program is via the return value and the names of the (local) variables in the program dos not matter. They must not be the same as the variables in the worksheet.

If you really need a function because you intend to call it with different initial values sigma[1, you should define it as epsilon(delta) and not of delta[i.  But I guess you just want the variable epsilon as a vector.

 

I see that you obviously do not just want a vector epsilon but also the corresponding vector delta, right?

You can do it that way

Werner_E_6-1655485573521.png

 

or I would prefer this

Werner_E_3-1655485295405.png

 

And of course you may plot epsilon over sigma if you like

Werner_E_4-1655485351616.png

 

P6 worksheet attached