Why do I keep getting this error message?

조회 수: 3 (최근 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 CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by