why will my function not take my array 'slope' as an answer. I am writing code to differentiate an equation by finding the average gradient.
Show older comments
error messages
function ret4=numerical_df(self)
x=[0.00000 0.000002 0.000004 0.000006 0.000008 0.000010]
y=[0 0 0 0 0 0 ]
slope=[0 0 0 0 0 0 ]
for n=1:6
y(n)=(self.a*x(n)*x(n)*x(n))+(self.b*x(n)*x(n))+(self.c*(n))+self.d;
end
for n=1:6
dx=x(n+1)-x(n);
dy=y(n+1)-y(n);
slope(n)=dy/dx;
end
ret4=slope
% ?????????
% for next question do differnce between df values
end
Error using my_maths_class/numerical_df
Too many input arguments.
Index exceeds the number of array elements (6).
Error in my_maths_class/numerical_df (line 74)
dx=x(n+1)-x(n);
2 Comments
Torsten
on 24 Mar 2022
y(n)=(self.a*x(n)*x(n)*x(n))+(self.b*x(n)*x(n))+(self.c*x(n))+self.d;
instead of
y(n)=(self.a*x(n)*x(n)*x(n))+(self.b*x(n)*x(n))+(self.c*(n))+self.d;
Tom Kirkland
on 24 Mar 2022
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!