# 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

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