33 views (last 30 days)

Show older comments

dt = 0.001; %time step

dx = 0.1; %step in x direction

% both value should satisfy the equation alpha*dt/(dx)^2<=0.5

lamda = dt/(dx^2);

t = 0:dt:15; %time interval (changable due to your desighn)

x = 0:dx:1; %x-axis interval (changable due to your desighn)

q_x=(100*sin(pi*x)); %define q(x) function

N = length(x)-1; %interval (changable due to your desighn)

T=[]; %Dynamic size array

T = zeros(length(t),length(x)+2); %define initial condition

for j=1:length(t)-1

for i= 2:N+2

% define the partial eauation in finite difference form

(T(j+1,i-1)*-lamda)+(T(j+1,i)*(1+2*lamda))+(T(j+1,i+1)*-lamda)= dt*q_x(i-1)+T(j,i);

end

-T(j+1,1)-2*dx*T(j+1,2)+T(j+1,3) = -20*dx; %first boundary condition (change it to your case)

-T(j+1,N+1)-2*dx*T(j+1,2)+T(j+1,N+3) = 20* dx; %second boundary condition (change it to your case

end

this is my error message :

Error: File: Parapolic_PDE_HW4.m Line: 20 Column: 71

Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.

Adam Danz
on 8 Apr 2021 at 21:30

Edited: Adam Danz
on 8 Apr 2021 at 22:21

>Why do I keep getting this error message?

(T(j+1,i-1)*-lamda)+(T(j+1,i)*(1+2*lamda))+(T(j+1,i+1)*-lamda)= dt*q_x(i-1)+T(j,i);

% ------------------------------------------------------------^

This line is the problem.

Everything to the left of the equal sign is interpreted as an output.

You can't perform operations directly within the outputs.

Walter Roberson
on 9 Apr 2021 at 0:13

no, im trying to solve for T , and equal it with -20*dx

Generally speaking, there are three situations:

- in one case, the left and the right side both contain terms whose values are all known, except for T, and T appears in linear form. In this situation, rewrite the terms to isolate T to the left hand side, and then you just have to execute the right hand side to get the value for T
- in the second case, the left and right side both contain terms whose values are all known, except for T, and T appears in polynomial form. In this situation, rewrite the terms to form a single polynomial in T, and form a vector of coefficients of T, and use roots() to get the numeric solutions; you might need to filter out the solutions (such as to remove the ones that include complex coefficients)
- in the third case, the left and right side both contain terms whose values are all known, except for T, and T appears in nonlinear form. In this situation, rewrite the terms to form a single expression on one side , and 0 on the other side of the equation, and form an anonymous function from the expression (without the implied "== 0"), and use fzero() or fsolve() to find a value for T.

Using the Symbolic Toolbox can make it much easier to do the rewriting -- or just vpasolve() or solve() the == equation form without rewriting.

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!