Error using inline/subsref (line 14) Too many inputs to inline function.

조회 수: 8 (최근 30일)
Greetings, my code run with error message of 'Error using inline/subsref (line 14) Too many inputs to inline function.'
This is where I used inline function.
df = vectorize(inline(get(handles.edit8,'String')))
f = vectorize(inline(get(handles.edit9,'String')))
When I run with the string of ' df(x,y) = 4.*exp(0.8.*x)-0.5.*y' and ' f(x) = (40.*exp(-x./2).*exp((13.*x)./10))./13 - (14.*exp(-x./2))./13', the code run perfectly.
However, when i run with this string ' df(x) = -2.*x.^3+12.*x.^2-20.*x+8.5' and 'f(x) = - x.^4./2 + 4.*x.^3 - 10.*x.^2 + (17.*x)./2 + 1', it has the error message.
Need help for this issue and it is very much appreciated! Thanks :)

채택된 답변

Steven Lord
Steven Lord 2016년 12월 1일
The way you've described the problem, it sounds like whatever is invoking the inline object will pass 2 inputs into df, but when you construct the inline in the second case it only detects one variable in the expression (using symvar) and so inline will construct an object that only accepts one input.
I strongly suggest that you use str2func to create an anonymous function instead of creating an inline object.
  댓글 수: 1
James Thiem
James Thiem 2016년 12월 2일
Hi Steven. Thanks for your reply.
if true
% code
endI modified the code as follows:
df =str2func(get(handles.edit8,'String'))
f = str2func(get(handles.edit9,'String'))
and my string for df and f respectively:
' @(t,y) - 2.*y + t.^2'
' @(t) (3.*exp(-2.*t))./4 - t./2 + t.^2./2 + 1./4'
My outputs are:
df =
@ @(t,y) - 2.*y + t.^2
f =
@ @(t) (3.*exp(-2.*t))./4 - t./2 + t.^2./2 + 1./4
But I got this error message:
Undefined function ' @(t,y) - 2.*y + t.^2' for input arguments of type 'double'.
It may due to the usage of df in the equation:
Error in rk3 (line 32) k1=h*df(T(j),Y(j));
Your help is much appreciated! Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Star Strider
Star Strider 2016년 12월 1일
It is difficult to determine exactly what you are doing. Your inline function takes only one input, 'String', so you can only pass one argument to it in any one call to it.

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by