Pde heat diffusion solution

m = 100
delta_z = 0.015
delta_t = 0.15
z= delta_z : delta_z : 1-delta_z
print(z)

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
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);
plot(j,u(n,j))

You seem to have forgotten to include your question. Also maybe can you put your code in code blocks? It’s not legible and the * get parsed as markdown italics

4 Likes

1 Like

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…

5 Likes

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.

8 Likes

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.

2 Likes

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?”…

5 Likes

m = 10000
delta_z = 0.015
delta_t = 0.15
z= delta_z : delta_z : 1-delta_z
print(z)

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

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);
plot(j,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.

4 Likes

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
Stacktrace:
 [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.

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.

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.

2 Likes