- #1
qspeechc
- 844
- 15
I have this assignment:
https://vula.uct.ac.za/access/content/group/317a243a-d926-4470-804c-7d46e296ab63/ass3_07.pdf
Although, I don't know if you'll be able to access that.
I am busy with task 2 in the file above.
Anyway, I am trying to write an M-File for a function g. g has two input arguments, a function f(x), and a x-value of the function. The file is then meant to use Newton's Method to approximate the gradient at x.
Here is my code:
>>function y = g(f(x), x)
>>y = (f(x+h) - f(x))/h;
I have found the best value for h in a previous bit of code.
In the command window I try to evaluate a functions' gradient at a point thus:
>>g(x^2, 2)
Meaning f(x) = x^2 and x = 2, but I get the error:
? Error: File: F:\My Documents\MATLAB\Numerical Methods\g.m Line: 1 Column: 17
Unbalanced or misused parentheses or brackets.
The same for
>>g(x.^2, 2)
>>g('x^2', 2)
>>g('x.^2', 2)
But I can not see where I have "Unbalanced or misused parentheses or brackets" in the line:
>>function y = g(f(x), x)
What is my error, and how do I correct it? Thanks.
https://vula.uct.ac.za/access/content/group/317a243a-d926-4470-804c-7d46e296ab63/ass3_07.pdf
Although, I don't know if you'll be able to access that.
I am busy with task 2 in the file above.
Anyway, I am trying to write an M-File for a function g. g has two input arguments, a function f(x), and a x-value of the function. The file is then meant to use Newton's Method to approximate the gradient at x.
Here is my code:
>>function y = g(f(x), x)
>>y = (f(x+h) - f(x))/h;
I have found the best value for h in a previous bit of code.
In the command window I try to evaluate a functions' gradient at a point thus:
>>g(x^2, 2)
Meaning f(x) = x^2 and x = 2, but I get the error:
? Error: File: F:\My Documents\MATLAB\Numerical Methods\g.m Line: 1 Column: 17
Unbalanced or misused parentheses or brackets.
The same for
>>g(x.^2, 2)
>>g('x^2', 2)
>>g('x.^2', 2)
But I can not see where I have "Unbalanced or misused parentheses or brackets" in the line:
>>function y = g(f(x), x)
What is my error, and how do I correct it? Thanks.