Error using ==> inline.subsref at 14 Not enough inputs to inline function.
1 次查看(过去 30 天)
显示 更早的评论
hi guys
Please if anyone can help me with my code. i face an error that says
**Error using ==> inline.subsref at 14
Not enough inputs to inline function.
x1=-4; x2=5;
F=inline('4*(sqrt(x1^2 + (10-x2)^2 )-10)^2 + 0.5*(sqrt(x1^2 + (10+x2)^2 )-10)^2 -5*(x1+x2)','x1','x2');
for j=1:200
s1=-dF1;
s2=-dF2;% dF1,dF2 can be found
x3=x1+s1*h;
x4=x2+s2*h;
%the problem is i want to use inline function as function of (h).
g=4*(sqrt(x1^3 + (10-x4)^2 )-10)^2 + 0.5*(sqrt(x3^2 + (10+x4)^2 )-10)^2 -5*(x3+x4).
f=inline('g','h');
% later in my loop i will use f(a) where a is known but i always got
*** Error using ==> inline.subsref at 14
Not enough inputs to inline function.
What I need is f as function in h so i can work with.
0 个评论
采纳的回答
Walter Roberson
2012-3-18
Anonymous functions are easier.
F = @(x1, x2) 4*(sqrt(x1^2 + (10-x2)^2 )-10)^2 + 0.5*(sqrt(x1^2 + (10+x2)^2 )-10)^2 -5*(x1+x2); %you do not appear to use F!
g = @(x1, x2, h) 4*(sqrt(x1^3 + (10-(x2+s2*h))^2 )-10)^2 + 0.5*(sqrt((x1+s1*h)^2 + (10+(x2+s2*h))^2 )-10)^2 -5*((x1+s1*h)+(x2+s2*h));
x1 = -4; %are these really constants??
x2 = 5; %are these really constants??
for j = 1 : 200
s1 = -dF1; %is this differential? You cannot differentiate an inline function or an anonymous function
s2 = -dF2; %differentiating what?
f = @(h) g(x1, x2, h);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!