필터 지우기
필터 지우기

How to write exponential function that accepts vectors ?

조회 수: 38 (최근 30일)
Rachel Dawn
Rachel Dawn 2018년 2월 13일
편집: James Tursa 2018년 2월 14일
o, say I want to write a function 's' for e^(10x) * e^(cosx)
function value=s(x)
value=exp(10*x)*exp(cos(x)) ;
this will only accept scalars. What if I wanted it to accept matrix & vector too? I know expm will allow matrix, but when I do s([1 2 4]) it spits out an error: Expected input to be a square matrix.
So, how can I have the same effect as ".^" with an exponential?

답변 (1개)

Star Strider
Star Strider 2018년 2월 13일
You have to use Vectorization (link) to do element-wise operations to use it with arrays.
Try this:
value = @(x) exp(10*x).*exp(cos(x));

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by