필터 지우기
필터 지우기

How to use solver in function

조회 수: 1 (최근 30일)
Kian
Kian 2012년 2월 11일
편집: Cedric 2013년 10월 8일
I have got a problem here.
I want to use solver within a function I m writing. To give you more details, suppose I want to write a function like:
function [a] = example
a = solve('14 = x^2')
end
Now the problem is how I can key in a variable instead of 14 in that solver. I mean suppose I have a variable been defined before like: d = 14, now I want to write my function as below, but it doesn't work :(
function [a] = example
d = 14
a = solve('d = x^2')
end
Any help?

채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 11일
syms x
a = solve(x^2 - d)
Alternately,
d = 14
a = solve(subs(sym('d = x^2'), 'd', d));
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 2월 12일
If you have a number in symbolic form which does not contain any unresolved symbols, then use double() to convert it to double precision number. Otherwise use char() and print the result as a string.
Kian
Kian 2012년 2월 12일
Thank you very much Walter. Both of the problems were solved.
Thank you again.

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

추가 답변 (1개)

shoubhik chakraborty
shoubhik chakraborty 2012년 2월 12일
Walter,could you please answer my question(which is related to the question) at:

태그

Community Treasure Hunt

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

Start Hunting!

Translated by