collect like terms, and substitute values for i
조회 수: 14 (최근 30일)
이전 댓글 표시
I have this equation:
dT = (a/r)*((T_i+1 - T_i-1)/2*dr) + r*((T_i+1 - T_i + T_i-1)/dr^2) + q/cp*rho;
I want to simplify this and collect like terms, as in T_i+1, T_i and T_i-1.
I also want to be able to plug in values for i, such as 1, n-2, n-1 and so on.
I tried a few things like this:
% Clear the workspace and the command window
clear; clc;
% Declare the symbolic variables
syms a dr T1 Ti T2 r q cp rho
% Define the expression
dT = (a/r)*((T1 - T2)/2*dr) + r*((T1 - Ti + T2)/dr^2) + q/cp*rho;
% Expand the expression to combine like terms
dT_expanded = expand(dT);
% Collect the terms for T1, Ti, and T2
[T1_coeff, T1_term] = coeffs(dT_expanded, T1, 'All');
[Ti_coeff, Ti_term] = coeffs(dT_expanded, Ti, 'All');
[T2_coeff, T2_term] = coeffs(dT_expanded, T2, 'All');
% Display the collected terms for T1, Ti, and T2
disp("Terms for T1:")
disp(T1_term)
disp("Terms for Ti:")
disp(Ti_term)
disp("Terms for T2:")
disp(T2_term)
;;;;;;
%and more simply
dT = simplify((a/r)*((T1 - T2)/2*dr) + r*((T1 - Ti + T2)/dr^2) + q/cp*rho)
% Display the simplified expression
disp(dT);
a1 = collect(dT, T1)
b1= collect(dT, Ti)
c1=collect(dT, T2)
d1=q/(cp*rho)
But neither of these are giving me what I want.
댓글 수: 0
채택된 답변
Walter Roberson
2023년 4월 29일
You do not say clearly what you do want.
% Clear the workspace and the command window
clear; clc;
% Declare the symbolic variables
syms a dr T1 Ti T2 r q cp rho
% Define the expression
dT = (a/r)*((T1 - T2)/2*dr) + r*((T1 - Ti + T2)/dr^2) + q/cp*rho;
% Expand the expression to combine like terms
dT_expanded = expand(dT);
% Collect the terms for T1, Ti, and T2
[T1_coeff, T1_term] = coeffs(dT_expanded, T1, 'All');
[Ti_coeff, Ti_term] = coeffs(dT_expanded, Ti, 'All');
[T2_coeff, T2_term] = coeffs(dT_expanded, T2, 'All');
% Display the collected terms for T1, Ti, and T2
disp("Terms for T1:")
disp((T1_term == T1_coeff).')
disp("Terms for Ti:")
disp((Ti_term == Ti_coeff).')
disp("Terms for T2:")
disp((T2_term == T2_coeff).')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!