フィルターのクリア

collect like terms, and substitute values for i

7 ビュー (過去 30 日間)
Kyle Langford
Kyle Langford 2023 年 4 月 29 日
回答済み: Walter Roberson 2023 年 4 月 29 日
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:")
Terms for T1:
disp(T1_term)
disp("Terms for Ti:")
Terms for Ti:
disp(Ti_term)
disp("Terms for T2:")
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)
dT = 
% Display the simplified expression
disp(dT);
a1 = collect(dT, T1)
a1 = 
b1= collect(dT, Ti)
b1 = 
c1=collect(dT, T2)
c1 = 
d1=q/(cp*rho)
d1 = 
But neither of these are giving me what I want.

採用された回答

Walter Roberson
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:")
Terms for T1:
disp((T1_term == T1_coeff).')
disp("Terms for Ti:")
Terms for Ti:
disp((Ti_term == Ti_coeff).')
disp("Terms for T2:")
Terms for T2:
disp((T2_term == T2_coeff).')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by