should i use using Linearalgebra
No, as has been said a few times now all your errors here are very basic syntax errors, which will not be helped by any packages. I donât think youâll get very far without reading the documentation, maybe starting with
https://docs.julialang.org/en/v1/manual/functions/
https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing
f
, a
, b
, c
, d
are only functions of j
(and constants) so I think they are meant to be evaluated into vectors. Otherwise, the function definitions should be placed outside of the while
loop.
@raman_kumar Are you trying to use functions or vectors in your implementation? You can use either.
Raman, you need to take a step back. The line you are âstuckâ at below is just the first line that Julia
couldnât make any sense of. The lines above that didnât error, but I donât think they are doing what you think they are doing either.
You canât just declare that equation above and expect u
to be solved for you. Thatâs not how computers work. You need to âwrite a numerical algorithmâ as stated in Part 1 of your assignment which will define the elements of u
in a loop. It should take the form u[n+1,j] = right-hand-side
such that you define u
at the next timestep and current spatial location based on u
at the current timestep and surrounding spatial locations.
You have some fundamental misunderstandings about the Julia language and numerical methods which are not all going to be solved in this thread. Read the Julia documentation and your course material and then formulate some more specific questions that are deeper than just get me my final plot so I can turn it in.
I second that.
Additionally, @raman_kumar from what I gather you seem to want to fill some kinds of vectors/arrays/whatever in a loop (vectors a
through f
looping over index j
). To do this, not only do you need a[i] = ...
instead of a(i) = ...
(as several people pointed out before), but you also have to define the vectors a
-f
first, ie. using a = zeros(10)
.
I believe the loop could be replaced by dot syntax, but suggesting that might add to OPâs confusion.
j=1
n=1
while j<=10
f[j]=1/(j*(delta_z)-1)
a[j] = (1+((2*(delta_t))/((delta_z)^2))+(((delta_t)(f[j])/(delta_z))-((delta_t)m(f[j]))
b[j] = (-1)(((delta_t)/((delta_z)^2))+((delta_t)f[j]/(delta_z)))
c[j] = (-1)((delta_t)/((delta_z)^2))
d[j] = (-1)
print(f[j],a[j],b[j],c[j],d[j])
j+=1
end
i replaced ( ) with ,but getting error
syntax: missing comma or ) in argument list
Again the error is a very basic syntax error, and the error message is telling you exactly whatâs wrong - you have unbalanced parentheses somewhere. Indeed it appears that almost all brackets you are using above arenât actually doing anything and can be removed. Replacing the delta symbols with unicode for legibility (note I had to use a lowerscript x
here because Unicode doesnât have lowerscript z
âŚ):
j=1; n=1
while j<=10
f[j] = 1/(j*뫉 - 1)
a[j] = 1 + 2*뫉/뫉^2 + 뫉*f[j]/뫉 - 뫉*m(f[j])
b[j] = -뫉/뫉^2 + 뫉*f[j]/뫉
c[j] = -뫉/뫉^2
d[j] = -1
print(f[j],a[j],b[j],c[j],d[j])
j+=1
end
Please use three backticks ``` to start and end a block of code. Then it will be correctly formatted.
@raman_kumar What @PetrKryslUCSD was suggesting is how to show your code in a reply here. You use your mouse to select the lines of code. Then type three backticks characters in the in the reply.
Then paste the code into the reply window. finally you type three backticks characters.
Like this:
```
area=width*length
```
Now - look carefully at the window to the right of the window you just posted in.
This is what we see in the forum when you press reply.Look at how the text appears.
@raman_kumar As people are saying here you need to take a step back.
Write what is called pseudo-code which is the words which describe your intention.
These pseudo-code lines can be written as comments.
Once you understand what the âflowâ of the algorithm is then you can start to put in lines of real code.
Also do NOT write all the lines of code at one time. Get a line correct. Get the next line correct.
Construct a loop - but make the contents of that loop simple. When you are confident the loop is working add more lines within the loop. Remember your pseudocode?
Use the power of the Julia REPL or the notebook system you are using - look how the REPL prints out what the last line returned.
Here is a pseudocode example from my very first day at Glasgow University which was taught by the late Dr Jennifer Haselgrove. We were taught top-down programming, if anyone stil remembers it!
Version 1
# Teach your cat to make tea
Version 2
# fill kettle with water
# boil the water on the stove
# place tea in the teapot
# pour boiling water into the teapot
# wait two minutes
# pour tea into a cup
You refuse to read our replies. I already told you why this wouldnât work:
People have been telling you to take a step back and figure out the basics first but you seem to stubbornly refuse to, which is a shame because these are suggestions that would benefit you, not us.
@raman_kumar You need to invest more time into your posts here if youâre to expect any help. It is not sufficient to just post code and errors and expect others to invest their time and energy into figuring out what youâre doing. Use words â describe what youâre doing, where youâre having trouble, what you think is the problem, etc. Folks here have asked you to explain more and given tips on how to do so, but youâve refused.
Beyond that, though, it appears as though your professor has explicitly disallowed asking for help. This may be a very serious violation of your academic integrity policies and I wouldnât be surprised if your professor were here.
For both those reasons, Iâm closing this topic. In the future, the way to ask questions about code is to actually ask them with words. Youâre interacting with real people here â you need to talk to us like weâre human. Please read the guidance in Please read: make it easier to help you before posting again.