Replacing symbolic variable with function input

조회 수: 11 (최근 30일)
Michal Walko
Michal Walko 2018년 10월 15일
답변: Steven Lord 2018년 10월 15일
Hi, I'm trying to replace my symbolic variable with whatever value is input into the function.
Here's some sample code:
function y=TestFunction(x)
syms G
y=G.^2
end
My result ends up having coefficients and is strictly in terms of G yet I can't figure out how to replace G with the input/function variable x. I tried doing subs but the documentation is a little confusing. I tried
x=G
y=subs(y)
as well as
x=G
subs(y,G,x)
I've probably gone through every possibility/variation of subs except the right one. I suspect it's painfully simple. Anyone have any ideas? I'm thinking there might be a way to do this without having G be symbolic but it eludes me.
Obviously the actual code is much longer but this is the issue summarized.
Thanks!

답변 (1개)

Steven Lord
Steven Lord 2018년 10월 15일
For your sample code, you don't need to use syms at all.
function y = TestFunction(x)
y = x.^2;
end
Show an example that's somewhat closer to your actual problem and we may be able to offer some suggestions.

카테고리

Help CenterFile Exchange에서 Functional Programming에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by