Why do I keep getting this error message?

3 次查看(过去 30 天)
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 个评论
DGM
DGM 2021-4-8
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.
Mohammad Adeeb
Mohammad Adeeb 2021-4-8
no, im trying to solve for T , and equal it with -20*dx

请先登录,再进行评论。

回答(2 个)

Adam Danz
Adam Danz 2021-4-8
编辑:Adam Danz 2021-4-8
>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 个评论
Adam Danz
Adam Danz 2021-4-8
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);
Mohammad Adeeb
Mohammad Adeeb 2021-4-8
i have to put all the terms because they are one equation

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2021-4-9
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.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by