subsvar

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Symbolics tools
Introduced first in SolidGeometry 4.2, Creation date: 2018-06-29, Last change: 2025-09-14

replaces several symbols in an equation

Description

This function is required to substitute several symbols or terms in a symbolic equation

See Also: symsofequation , solveequations

Example Illustration

 missing image of subsvar(f,sv,)

Syntax

g=subsvar(f,sv,[])

Input Parameter

f: original term / equation
sv: array of symbols to substitute or [s1 v1; s2 z2];

Output Parameter

g: resulting term / equation

Examples


syms x(t) D C F m; dx=diff(x); ddx=diff(x,2);
f=dsolve(m*ddx+D*dx==0, x(0)==0,x(6)==1); sv=symvar(f)
subsvar(f,[D m],[1 1])
subsvar(f,[D 1;m 1])




Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, subsvar, is designed to substitute multiple symbols or terms in a symbolic equation. It is part of the SYMBOLICS TOOLS class and was introduced in SolidGeometry 4.2.

Input Parameters

Output Results

Algorithm Steps

  1. Initialize an empty array nv.
  2. Check if there are at least three input arguments and if the third argument is not empty. If so, assign it to nv.
  3. If there are fewer than three arguments, assume sv is a matrix with symbols in the first column and values in the second. Assign these to sv and nv respectively.
  4. Initialize g with the original equation f.
  5. Iterate over each symbol in sv and substitute it with the corresponding value in nv using the subs function.
  6. If no output is requested (i.e., nargout==0), display the result in a pretty format.

Example Usage

Consider the following example where syms x(t) D C F m; defines symbolic variables and dx=diff(x); ddx=diff(x,2); defines derivatives. The function dsolve is used to solve a differential equation, and subsvar is used to substitute values for D and m.

Example code:

syms x(t) D C F m; 
dx=diff(x); 
ddx=diff(x,2);
f=dsolve(m*ddx+D*dx==0, x(0)==0,x(6)==1); 
sv=symvar(f);
subsvar(f,[D m],[1 1]);
subsvar(f,[D 1;m 1]);
Algorithm explaination created using ChatGPT on 2025-08-19 00:12. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21