Why do I keep getting this error message?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 '=='.
3 Kommentare
DGM
am 8 Apr. 2021
If you're writing symbolic equations, you'd need to assign them to a variable (and use == to denote equality).
eqn1 = (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);
That said, nothing here appears to be set up for symbolic operations.
Antworten (2)
Adam Danz
am 8 Apr. 2021
Bearbeitet: Adam Danz
am 8 Apr. 2021
>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.
3 Kommentare
Adam Danz
am 8 Apr. 2021
Your question was "Why do I keep getting this error message" and my answer explains why.
Are you asking a new question now?
Hint: Save the output like this, then perform operations on the output in a separate line.
T(j+1,i-1) = dt*q_x(i-1)+T(j,i);
Walter Roberson
am 9 Apr. 2021
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.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!