solve nonlinear equation
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I write a method to solve any equation
function [ result ] = get( func )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
result=solve(func);
end
when I run it on command window,I get an error.
>> f=@(x) 2*x+1
f =
@(x)2*x+1
>> [ result ] = get( f )
??? Error using ==> error
Function is not defined for 'function_handle' inputs.
Error in ==> solve>getEqns at 182
error('symbolic:solve:errmsg1', ...
Error in ==> solve at 67
[eqns,vars] = getEqns(varargin{:});
Error in ==> get at 4
result=solve(func);
so how can I fix the error
0 comentarios
Respuestas (3)
Oleg Komarov
el 31 de Mayo de 2011
You have to convert the anonymous function handle to a string function:
fh = @(x,y) 2*x+1-2*y;
% Convert to string
fs = func2str(fh);
% Extract only function part w/o @(.)
fs = regexprep(fs,'@\([\w,]+\)','');
% Solve
solve(fs)
4 comentarios
Matt Fig
el 1 de Jun. de 2011
Read the rest of the post. FUNC2STR is working just like Oleg showed...
Walter Roberson
el 1 de Jun. de 2011
solve() only applies to symbolic expressions. If you are going to use symbolic expressions you might as well do so from the start and save the trouble about constructing function handles.
4 comentarios
Walter Roberson
el 1 de Jun. de 2011
If this is for an assignment, then it would help us to read the assignment question, as then we would not suggest things you cannot use.
Walter Roberson
el 1 de Jun. de 2011
If the assignment prohibits you from passing around symbolic variables, then why does it permit you to use solve(), the symbolic equation solver?
Eman Ahmed Elsayed
el 1 de Jun. de 2011
1 comentario
Oleg Komarov
el 1 de Jun. de 2011
What do you mean you have the same problem? Post the whole code you're using and the error message.
Ver también
Categorías
Más información sobre Nonlinear Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!