Q = []
for i=1:n_const:
for j=1:n_const:
if i <= n_prev && j <= n_prev:
if i <= n_prev:
Q_prev[i,j] = Q_aug[i, j-n_prev]
else j <= n_prev:
Q_aug[j, i-n_prev] = Q_aug_diag[i-n_prev, j-n_prev]
end
end
end
push!(Q_aug_diag, Q_aug)
end
could you correct me if I did it right here? I am not sure about this, and using push!(). Am I right about here? any thoughts? Thanks!
Q_aug= []
for i=1:n_prev:
for j=1:n_added:
Q_aug[i,j]= calc_dot((const_prev[i][1], const_prev[i][2], const_added[j][1], const_added[j][2]), K, y)
end
end
function body of calc_dot is in this gist. Am I right about on Q_aug? could you give me your possible feedback if I was wrong about it? Thanks again for your help in this community!
how that supposed to be corrected? should I use psuh!()? I am not quite sure about what I wrote. How could you write Q_aug in simplistic way? any idea?
Frankly, I think you should take a step back and try to work through the manual. IMO, you seem to be lacking basic understanding of Julia and its syntax (which of course is perfectly fine and expected for a beginner!). I don’t think it is too helpful to successively ask for rewrites of blocks of code here.
Also, I don’t fully understand why you would expect or want the same syntax to work in python and Julia. After all, these are different programming languages.
I looked into manual and followed above useful comments from @ Seif_Shebl about the syntax. But I don’t understand why you think doing this way is wrong. Can you comment what was wrong about this?
Q_aug= []
for i=1:n_prev:
for j=1:n_added:
Q_aug[i,j]= calc_dot((const_prev[i][1], const_prev[i][2], const_added[j][1], const_added[j][2]), K, y)
end
end
it is not quite straightforward to me at first place because there is no MWE that I could make. For julia learner, I looked into julialang documentation, and sample project that I am learning. Could you show what’s the valid way to write above? any idea?
As @carstenbauer said, you should go through the manual to get yourself familiar with the main syntax of Julia as you would do when learning C or MATLAB for the first time. You will find useful yet simple examples that will sharpen your skills in Julia. For example, the Repeated Evaluation section will teach you some ways to write and understand loops.
As for your code segment above, here are some comments:
The Q_aug= [] will create a Vector with 0 elements of type Any, this will not be efficient in Julia because it is type-unstable
There is no :s at the end of fors or ifs like in Python
Finally, julia is a different language from Python, so you should learn it and don’t expect Julia code to be identical to Python code. Julia is a newer language with cool modern features not available in Python or even in most similar-age languages, so why not put the effort to learn it and it will pay you off later?
Did you test it? You will get an error message. To learn any programming language you have to code, test your code all the time, work through the errors, and have the manual and/or other references at your side.
could you direct me best sources for beginners like me? I jumped into Julia for project needs and looked into built-in functions and documentation, but I think not everything is crystal clear to newbie. I will take your comment series for learning. Thanks!