How to substitute multiple values in symbolic matrix?
Show older comments
Hi, How to substitute multiple values in symbolic matrix? With function subs, we can substitute only single value in expression. Writing nested subs(subs(...)) can work but it becomes tedious. Here is sample code:
syms x y z w
N=[ 1y+y+z,x/2 - y/3 + z/3, x*y, x+z];
Is there any way to substitute values to w,x,y,z in single line? I guess then I have to define variables like x(1), x(2) etc. and have to use for loop to change values. Is this approach correct or is there any better way?
Accepted Answer
More Answers (1)
Youssef El Seblani
on 31 Mar 2018
Edited: Walter Roberson
on 31 Mar 2018
clc
clear
syms x y z w
N=[ w+y+z,x/2 - y/3 + z/3, x*y, x+z]
A=sym('X',[1,4])
N(A) = subs(N,[x, y, z, w],A)
for example
N(1,2,3,4)
2 Comments
Walter Roberson
on 31 Mar 2018
This will not work if I recall correctly. You cannot use a vector of symbolic variables after a variable name in order to define a function of multiple parameters. Instead each variable must be a separate parameter.
Youssef El Seblani
on 8 Apr 2018
Categories
Find more on Common Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!