Why do I keep getting this error message?

4 ビュー (過去 30 日間)
Mohammad Adeeb
Mohammad Adeeb 2021 年 4 月 8 日
回答済み: Walter Roberson 2021 年 4 月 9 日
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 Center および File ExchangeNumeric Solvers についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by