How to solve this problem: Not enough input arguments. Nonlinear equations, Vegstein

1 次查看(过去 30 天)
function [ root, k ] = veg(f,a,b)
e = 0.00001;
x0 = a;
x1 = b;
xn = x1 - (f(x1)*(x1-x0)/(f(x1)-f(x0)));
k = 1;
while (abs(x1-xn)>e)
k = k+1;
x0 = x1;
x1 = xn;
xn = x1 - (f(x1)*(x1-x0)/(f(x1)-f(x0)));
end
root = xn;
end
[x1f1_vegstein,k] = veg(f1,1.4,1.8);
error1 = abs((abs(x1f1_vegstein)-abs(x1f1))/x1f1);
table(x1f1_vegstein,k,error1)
function f = f1(x1)
f = 2*x1.^4+8*x1.^3-18*x1.^2-1;
end
Not enough input arguments.
Error in f1 (line 2)
f = 2*x1.^4+8*x1.^3-18*x1.^2-1;
Error in lr6 (line 77)
[x1f1_vegstein,k] = veg(f1,1.4,1.8);

回答(1 个)

Govind Narayan Sahu
编辑:Govind Narayan Sahu 2020-7-14
use @ symbol with f1 as given below:
[x1f1_vegstein,k] = veg(@f1,1.4,1.8);
After that you will get the root but also get the error since you have not created the variable x1f1. Please check.

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by