필터 지우기
필터 지우기

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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by