Pde heat diffusion solution

With “question” I don’t mean your assignment. I mean what are you expecting from your code and what happens instead. What exactly do you need help on? Few people will solve the entire exercise for you. Maybe using a few words to explain what you are trying to do doesn’t hurt either…


It looks like you might have overlooked the paragraph right underneath the due date?

This forum doesn’t have an official homework policy, but it’s unlikely that someone will solve this for you. You might have more luck with a very targeted question if you run into a specific error, and post reproducible code.


is there need to add linalg

Please make sure you read Please read: make it easier to help you, particularly the bit about providing copy-pastable MWEs rather than screenshots.


Regarding Homework Policy, there was an attempt to establish one, but it fizzled out a while ago. Maybe we should revive that effort.

I don’t think it’s been “formalized” in the way the “Make it easier to help you” post has been.

That said, this post feels to be more in the category of “please solve this for me” instead of a clear “this is what’s going wrong, can you help me?” or “I expected this, but that happens instead, why?”…


m = 10000
delta_z = 0.015
delta_t = 0.15
z= delta_z : delta_z : 1-delta_z

while j<=10
a(j) = (1+((2*(delta_t))/((delta_z)^2))+(((delta_t)f(j))/(delta_z))-((delta_t)m(f(j))))
b(j) = (-1)
c(j) = (-1)
d(j) = (-1)


u= zeros(4,4)
u[1,end] = 0
u[1,1] = 1

a(j)*u[n+1,j] + b(j)*u[n+1,j+1] + c(j)*u[n+1,j-1] + d(j)*u[n,j] = 0

using Plots
j = 1:100; u(n,j);

@raman_kumar I don’t think there are any magicians among us who can divine your thoughts. Please explain what your question is and where you are stuck.


i am stuck at this line

And what are you trying to do? a(j) is a function call, is that what you’re after? Your error can be minimally reproduced by this:

julia> a(i) + b(j) = 0
ERROR: syntax: "a(i)" is not a valid function argument name around REPL[20]:1
 [1] top-level scope
   @ REPL[20]:1

Which tells you that when seeing a(i) on the left hand side of an equal sign, Julia expects you to define a function, but adding to function calls on the LHS is not valid syntax. What are you actually trying to do with this line?

i want to plot u[n,j]

In your code above you have plot(j, u(n, j)), rather than u[n, j] - which one is it? It appears that u is a 4x4 matrix, so u(n, j) won’t work because it tries to call a function u (that’s what round brackets do), while u[n, j] wouldn’t work because you define j = 1:100 and u doesn’t have 100 columns.

1 Like

All indexing must be with square brackets. Parentheses are for function calls. Replace a(j), b(j), … with a[j], b[j], … in this line and the definitions above it.

1 Like

syntax: “(a(j) * u[(n + 1), j])” is not a valid function argument name around In[5]:1

but i have defined it as a(j)

I’m not sure that a, b etc are supposed to be containers being indexed rather than functions - in the loop above it just says a(j) = ... so maybe it’s supposed to define a function?

In any case @raman_kumar the error about invalid function argument names I have explained above, I think to make progress you should start by reading the Julia documentation to understand the basic concepts of working with functions, vectors, matrices, indexing etc. in Julia.


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




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.