필터 지우기
필터 지우기

Substituting numbers into a matrix with symbolic values

조회 수: 3 (최근 30일)
Colin
Colin 2012년 4월 21일
For my code, I set certain values like x, y , z to be symbolic at the beginning. I wanted to create a matrix with these in them, then later sub in values.
If I have a matrix currently in the form: [x+y; y+z; z+x; y+z]
How can I set it up to calculate each entry when x, y, and z are certain numerical values?
I tried a for loop such as:
for x = 1
for y = 2
for z = 3
[A] = [matrix of variables with symbolic variables]
end
end
end
but I just get a return of my symbolic matrix and not numerical values like I want.
Any suggestions or help? Thanks in advance

채택된 답변

Hossein
Hossein 2012년 4월 21일
Is it possible to write a function that does that? like this:
function Amat=Amat(x,y,z)
Amat=[x+y;y+z;z+x;y+z];
end
now whenever you want you call Amat(1,2,3) and it returns the vector or matrix that you desire. The good thing is that you can later on pass the handle of your matrix (function) to another function. I hope this is what were looking for.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 4월 21일
subs([x+y;y+z;z+x;y+z], {x,y,z}, {1,2,3})

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by