Substitute Expressions in Matlab

Substitute parts of a equation (mathematical expression). Helpful in simplifying long expressions.
486 Downloads
Updated 20 Aug 2009

View License

This function provides a supplement to the Matlab Symbolic toolbox to substitute and simplify long expressions. Maple does not provide this functionality.
input-- Input expression that has some terms to be substituted.
>> input='a^2-2b+c-3';
>> inputmode=1;
Note that 'inputmode=1' indicates that the input is a
string expression;

subexp-- If ‘subexp’ can be found inside 'input' expression, then all the instances of ‘subexp’ are substituted with the expression 'var'
outputmode-- output is a character string if ‘outputmode=1’;

Note: Read help for the other options.

EXAMPLE:

input='a^2-2*b+c-3';
subexp='c+a^2';
var='Z'
inputmode=1;
outputmode=1;
out=SubsExp(input,subexp,var,inputmode,outputmode);

ANSWER
>>out =Z - 2*b - 3

Cite As

Shaminda Subasingha (2024). Substitute Expressions in Matlab (https://www.mathworks.com/matlabcentral/fileexchange/25070-substitute-expressions-in-matlab), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.4.0.0

Made the introduction simpler. Changed the summary.

1.1.0.0

Corrected some typos in the introduction

1.0.0.0