collect like terms, and substitute values for i
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kyle Langford
am 29 Apr. 2023
Beantwortet: Walter Roberson
am 29 Apr. 2023
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Apr. 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!