I am trying to create a function with Matlab V6.0.0.88 and it is not working.
Show older comments
I tried for example using the following code given in the wikipedia page about the secant method
f=@(x) x^2 - 612;
x(1)=10;
x(2)=30;
for i=3:7
x(i) = x(i-1) - (f(x(i-1)))*((x(i-1) - x(i-2))/(f(x(i-1)) - f(x(i-2))));
end
root=x(7)
And I receive the following error message
??? f=@(x) x^2 - 612;
|
Error: "identifier" expected, "(" found.
I have tried a few things, but I am unable to create a function. Even the following code, who is part of the Matlab help menu, found while searching for 'function', does not work
function [mean,stdev] = stat(x)
n = length(x);
mean = sum(x)/n;
stdev = sqrt(sum((x-mean).^2/n));
This piece of code returns the error
??? Strings passed to EVAL cannot contain function declarations.
Can anyone help me with this? Thank you!
2 Comments
Jan
on 22 Aug 2017
Today I've selected your code and press the "{} Code" button to improve the readability of the question. Please do this by your own the next time. Thanks.
Patrick Soucy
on 22 Aug 2017
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!