MATLAB Answers

Array indices must be positive integers or logical values.

조회 수: 3(최근 30일)
Dilsah Bahçeci
Dilsah Bahçeci 2021년 5월 12일
답변: Star Strider 2021년 5월 12일
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
Dilsah Bahçeci
Dilsah Bahçeci 2021년 5월 12일
ı am gonna find x by using fzero function. How can ı correct in your opinion?

댓글을 달려면 로그인하십시오.

답변(1개)

Star Strider
Star Strider 2021년 5월 12일
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.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by