필터 지우기
필터 지우기

How to evaluate a function over a range of inputs

조회 수: 22 (최근 30일)
flemingtb
flemingtb 2018년 8월 3일
편집: Fangjun Jiang 2018년 8월 3일
This is probably really easy but i'm new to Matlab and can't figure out the syntax.
Example: F = ((1-n/(1+n))^2 n = [0:15]
Want to evaluate the function (F) for a given (n) is all... How do you set this up in ML?

답변 (2개)

Steven Lord
Steven Lord 2018년 8월 3일
You will need to use the element-wise or array versions of the division and power operators. See this documentation page for an explanation of the different between the element-wise / array operators and the matrix operators.
As a simple example of the difference, using the times array operator ".*" and the mtimes matrix operator "*":
A = [1 2 3; 4 5 6; 7 8 9]
B = [1 4 7; 2 5 8; 3 6 9]
elementwise = A.*B
matrix = A*B

Fangjun Jiang
Fangjun Jiang 2018년 8월 3일
편집: Fangjun Jiang 2018년 8월 3일
The OP is probably asking for this
>> F=@(x) ((1-x/(1+x)))^2
F =
function_handle with value:
@(x)((1-x/(1+x)))^2
>> F(15)
ans =
0.0039
More common way is to write the following and save it as F.m then you can call and run F(1)
function out=F(x)
out=((1-x/(1+x)))^2;

카테고리

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

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by