vectorization of anonymous function?

조회 수: 2 (최근 30일)
Jan Valdman
Jan Valdman 2016년 12월 18일
댓글: Jan 2016년 12월 18일
I managed to vectorize the function below using inline command:
u_function=inline(vectorize('sin(x*y*z^2)'),'x','y','z') x=[1 2 3 4]; y=[3 4 3 4]; z=[1 2 4 4]; u=u_function(x,y,z)
How do I rewrite it in terms of an anonymous function?
Cheers, Jan

답변 (1개)

Mischa Kim
Mischa Kim 2016년 12월 18일
편집: Mischa Kim 2016년 12월 18일
Jan, is the resulting u(x,y,z) also a 1-by-4?
How about:
u = str2func(vectorize('@(x,y,z)sin(x*y*z^2)'));
x = [1 2 3 4]; y = [3 4 3 4]; z = [1 2 4 4];
u_eval = u(x,y,z)
  댓글 수: 2
Jan
Jan 2016년 12월 18일
Move from Answer section (please pst comments in the comment section - Thanks)
Hi Mischa,
thank you, all vectors should have the size, yes. However, I am going to use more difficult forms of functions instead of x*y*z^2 and would like Matlab to put dots automatically (using vectorize?) within anonymous function. Is there a way to do it?
Jan
Jan 2016년 12월 18일
Mischa wrote: Jan, understood. Check out the updated answer above. Does this do the trick?

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by