필터 지우기
필터 지우기

solve nonlinear equation

조회 수: 1 (최근 30일)
Eman Ahmed Elsayed
Eman Ahmed Elsayed 2011년 5월 31일
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

답변 (3개)

Oleg Komarov
Oleg Komarov 2011년 5월 31일
You cannot solve a function handle.
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
Eman Ahmed Elsayed
Eman Ahmed Elsayed 2011년 6월 1일
func2str doesn't work with me
>> f=@(x) 2*x+1
f =
@(x)2*x+1
>> func2str(f)
ans =
@(x)2*x+1
It's return the same equation
Matt Fig
Matt Fig 2011년 6월 1일
Read the rest of the post. FUNC2STR is working just like Oleg showed...

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


Walter Roberson
Walter Roberson 2011년 6월 1일
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
Walter Roberson
Walter Roberson 2011년 6월 1일
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
Walter Roberson 2011년 6월 1일
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
Eman Ahmed Elsayed 2011년 6월 1일
I'm still have the same problem
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 6월 1일
What do you mean you have the same problem? Post the whole code you're using and the error message.

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

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by