How to evaluate a function over a range of inputs
62 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (2)
Steven Lord
el 3 de Ag. de 2018
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
0 comentarios
Fangjun Jiang
el 3 de Ag. de 2018
Editada: Fangjun Jiang
el 3 de Ag. de 2018
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;
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!