evaluating a function which is stored in a variable

Hi everyone
I'm going to evaluate a function which has two variables. imagine i have syms x y . func1 is a function of x and y, func2 is also a function of x and y, which i dont know what are they, I just know that both of them are function of x and y. now i want to evaluate (func1*func2) base on only x. how could i do that?
func1 = f1(x,y)
func2 = f2(x,y)
multiply = func1*func2
x = 12 ---> multiply = ?
surely the result is a function of y.

댓글 수: 4

KSSV
KSSV 2020년 12월 15일
You multiply func1 and func2..you will get this as a function of (x,y) and then substittute x.
The question is not clear, what do you mean you don't know what those function are?
syms x y
func1 = @(x, y) 2.*x + x.*y;
func2 = @(x, y) x.^y + 3.*y;
multiply = func1(12, y).*func2(12, y)
multiply =
(3*y + 12^y)*(12*y + 24)
those function are unknown, i just know that they are a function of x and y. after mulitpling i have a new function of x and y which is definitly unknown too. then i will get x from the other parts of program and now i want to evaluate the multiply function so i should have a function of y. I hope it is more clear now.
"I hope it is more clear now."
Not at all. You have tagged this question for "inline" (which has been obsolete for more than fifteen years) and "matlabfunction" and in the text you mention "syms" and show an example with none of these. That is three totally different kinds of functions and counting... If you want to get help on a specific type of function or equation that you already have defined in MATLAB then you need to be a lot more specific and clear with your explanation and example. If you are looking for advice on how to solve some equations that you have defined on paper then you need to explain that.

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

답변 (1개)

Matt J
Matt J 2020년 12월 15일
편집: Matt J 2020년 12월 15일
Here's one way. It will work whether f1, f2 are anonymous or symbolic.
multiply = @(x,y) f1(x,y).*f2(x,y)
g=@(y) multiply(12,y); %restrict to x=12

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2020년 12월 15일

댓글:

2020년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by