필터 지우기
필터 지우기

In symbolic expression how to include an expression that is a function of the symbolic variable?

조회 수: 1 (최근 30일)
I have an expression given as e.g.:
g = @(x) f*x
where f is a function of x and is defined as
f(x) = b if x > a
f(x) = c if x <= a
and a,b,c are constant numbers.
1. How to define this function? How can a parameter depend on the symbolic variable in a symbolic expression?
2. How can I multiply two expressions like this? What I want to get is:
g = @(x) a*x;
h = @(x) b*x;
gh = g*h; % I want to get gh = a*b*x^2;
It gives an error saying
"Undefined function 'mtimes' for input arguments of type 'function_handle'."
I also tried gh = @(f) g*h, which also doesn't work.

채택된 답변

Mischa Kim
Mischa Kim 2014년 4월 14일
편집: Mischa Kim 2014년 4월 14일
László, try
g = @(x) x*(c*(x<=a) + b*(x>a));
and
gh = @(x) g(x)*h(x);
  댓글 수: 2
László Arany
László Arany 2014년 4월 14일
Thank you, these work nicely and the first one is very elegant!
However, what if I have a more complicated function? Say I have to solve the dispersion relation inside the symbolic expression?
H = @(f) k*f;
where k = k(f) and it results from the nonlinear expression f^2 = k*g*tanh(k*S) with g=9.81; S=21? Can I solve this more complicated nonlinear equation inside a symbolic expression somehow?
Mischa Kim
Mischa Kim 2014년 4월 14일
I believe this one is similar to the other question I just answered, unless you mean something different by solve...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by