0

New to matlab and having difficulty with the syntax since im used to using mathematica.

In mathematica i can define two functions $f(x)=x$ and $g(x)=x^2$ and define a third function simply as $h(x)=f(x)g(x)$ where f(x) and g(x). How do i do the same process in matlab where f(x) and g(x) are just functions and not arrays or matrices?

Thanks in advance.

anonymous
  • 401
  • 2
    When f(x) and g(x) are given as vectors f and g, use f.*g – draks ... Mar 30 '16 at 10:45
  • all element is MATLAB are matrices. but you can right function with function m-file. note that the name of m-file must be the name of your function and the m-file must be at the scope of the other m-file which is using it. read about it all in here: www.mathworks.com/help/matlab/ref/function.html also what @draks offer is nice too. you can write your expressions array smart with dot operator like comment above – K.K.McDonald Mar 30 '16 at 10:46

1 Answers1

0

You can try anonymous functions like this:

f = @(x) x;
g = @(x) x^2;

h = @(x) f(x) * g(x);