How we can calculate using MATLAB for small values?

1 visualización (últimos 30 días)
Shafiq Roslan
Shafiq Roslan el 21 de Nov. de 2012
R = 1000;
cf = 0.001;
f(cf) = 4.04*cf.^0.5 + (cf.^0.5)*3.94*log(R*cf.^0.5) - 1
??? Attempted to access (0.001); index must be a positive integer or logical.

Respuestas (3)

Image Analyst
Image Analyst el 21 de Nov. de 2012
You don't need the (cf) if you just want the value of f for that value. Just use f by itself, like this:
R = 1000;
cf = 0.001;
f = 4.04*cf.^0.5 + (cf.^0.5)*3.94*log(R*cf.^0.5) - 1
You can turn it into a function if you want to pass it various values of cf as input arguments to a function, but it's not necessary if you just want the value of f and you can just specify what cf is before you calculate f, like I did above.

Akiva Gordon
Akiva Gordon el 21 de Nov. de 2012
You must first create an anonymous function to be able to evaluate the function like that:
This means "f" is a function with an input of "x". You would commonly see this on paper as f(x) = x+2;
f = @(x)(x+2);
a = 2;
This line evaluates "f" at the point "a" and stores it in "y".
y = f(a)
  2 comentarios
Akiva Gordon
Akiva Gordon el 21 de Nov. de 2012
Please visit the following link for more information on anonymous functions:
Jan
Jan el 21 de Nov. de 2012
@Akiva: You can edit your answer instead of appending a comment.

Iniciar sesión para comentar.


Star Strider
Star Strider el 21 de Nov. de 2012
Editada: Star Strider el 21 de Nov. de 2012
MATLAB considers f as a matrix as you have written it. You need to define f as a function. It is easiest to write it as an Anonymous Function:
R = 1000;
cf = 0.001;
f = @(cf) 4.04*cf.^0.5 + (cf.^0.5)*3.94*log(R*cf.^0.5) - 1;
fcf = f(cf)
results in:
fcf =
-441.9125e-003
You can also define it as a function of both cf and R if you want to:
f = @(cf,R) 4.04*cf.^0.5 + (cf.^0.5)*3.94*log(R*cf.^0.5) - 1;

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by