Array indices must be positive integers or logical values.

g=9.81;
m=95;
v=25;
t=10;
f(x)=m*g/x*(1-exp(-(x/m)*t));
Array indices must be positive integers or logical values.
I am taking this message. What is wrong at the code?

2 Comments

Most likely x is not a positive integer. What is the value of x ?
Are you actually trying to define a function of the independent variable x ?
ı am gonna find x by using fzero function. How can ı correct in your opinion?

Sign in to comment.

Answers (1)

That notation only will work in the Symbolic Math Toolbox. Use Anonymous Functions to create functions for numeric calculations outside the Symbolic Math Toolbox.
Perhaps —
g=9.81;
m=95;
v=25;
t=10;
f = @(x) m*g./x.*(1-exp(-(x/m)*t));
xval = 10;
x = fzero(@(x)f(x)-xval,100)
x = 93.1899
xv = linspace(-1,150);
figure
plot(xv,f(xv), x, xval,'rs')
The function will not cross the x-axis. It is possible to determine where it will reach a specific value.

Tags

Asked:

on 12 May 2021

Answered:

on 12 May 2021

Community Treasure Hunt

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

Start Hunting!