and in the final line of the program i want to calculate an integral, and this integral depends of the R value … for each R value i have a integral value … and i have to print a table of these values …
This is not a interval. 0.5:0.5:10 is a range (a compact representation of an array) and if by interval you mean this array then you should just not put it in another array. i.e. R = 0.5:0.5:10. If by interval you mean something else than you need to be more specific.
Assuming you actually want the range 0.5:0.5:10 I’ll assume that you get the idea of using [0.5:0.5:10] from matlab. [...] in matlab corresponds to [...;] in julia which concatenate the array so [0.5:0.5:10;] in julia works too although it adds an unnecessary convertion.
for a constant sigma value, = 0.6 for example, i calculated many things that i used later
so, when i do R=0.5:0.5:10; the values that i calculate can not calculate for many sigma values … and give this
rc0bc0gc0( sigma )
rc0 = brent(r->3Φl(r)+r*Φll(r),1.02,5)
gc0 = sqrt(Φ(rc0)+rc0*Φl(rc0)/2)
bc0 = rc0*sqrt(gc0^2-Φ(rc0))/gc0
rc0, bc0, gc0
end
rc0, bc0, gc0 = rc0bc0gc0( sigma ) (( ** the answers is here - three different values for a constant sigma )
When you post code, please post COMPLETE code, i.e. one can just copy-paste and run it. (The original one is good, the new one isn’t) Also please paste COMPLETE error and especially please READ and include backtrace. You were asking how to get sigma and now it’s pretty clear that your error is not at all from there anymore and in this case, please mention that you are asking questions in a different context now. Continuing in a single thread until you’ve fixed all problems in your code is certainly fine but you should explicitly state that or it is pretty confusing what you are actually asking about.
Note that AFAICT sigma isn’t being used in your function, (or it’s not called sigma I can’t tell). But if you are using a function that works with scalar input you should first figure out if it can accept vector input. Or you should use the rc0bc0gc0.(sigma) syntax to get an array of output corresponding to an array of input.
Easy there, Yichao. Please try to give new folks gentler nudges in favor of complete verifiable examples and be a little more gracious about their problems. I wouldn’t be surprised if the error message here was indeed a downstream problem that was a direct result from 0.319 ./ [0.5:0.5:10] not doing what leaoshark expected.
At the same time, @leaoshark, please don’t post the same problem multiple places simultaneously. I posted an answer at Stack Overflow before seeing this thread here. It just ends up duplicating effort and splintering the conversation. How to change a single value to a vector - JULIA - Stack Overflow
You are not actually using sigma in your function at all and is
rather using it as a global variable so changing what you pass to the
rc0bc0gc0 function won’t make any difference.
You are using sigma (as well as other values) as scalar. As I’ve
already said, you should figure out if you want to keep it that way
(and apply rc0bc0gc0 on each of the scalar values individually) or if
you want to “vectorize” rc0bc0gc0.
The two should be almost equivalent though one will give you an
array of 3-tuples (since that’s the return value of rc0bc0gc0) and the
other will give you three arrays.
After you fix the function parameter (i.e. 1), you can fix this by
adding . to appropriate places (i.e. where you want to apply element-wise
operation on the array)
I don’t know what you want so I’m not sure what’s better.
To repeat,
Also, on a closer look, I think you are still not posting the complete code. It’s unclear what brent.jl is. And you should also quote your code as code so that the format isn’t messed up and there isn’t missing characters. It’s unclear if it’s caused by formatting or mistake in the code that it’s very hard to tell where each variables are defined.
Yes, this is still far too hard for us to discern what’s going on here. Stack Overflow has some very nice advice on how to make it easier for folks to answer your question. Please take some time to read through this guide:
Am I understanding you correctly that this script works when sigma is a single number, but it fails when you change it into a vector of values?
You should change Φ, Φl, Φll, Veff, Veffl, Veffll to all take sigma as parameter and pass it around. You still need to decide what you want to get in the end though. Do you want three arrays of numbers, or an array of 3-tuples. As I’ve said, that determines where you need to add the .s and the two options would be in rc0bc0gc0 or on rc0bc0gc0 (i.e. modifying the function to call other functions in it with the . syntax or calling the function itself with the . syntax). It seems you should only need to fix rc0bc0gc0 and can leave the rest of the functions along though, after adding the sigma parameter.