MATLAB 引用公式求解方程:

例如:mx(1)=x+3;bm(2)=54./y ,(式中mx为多个方程,mx(1)只表示其中一个,同理bm也是,)
程序:syms x y
mx(1)=x+3;bm(2)=54./y ;
a=solve(‘y=mx(1)’,‘x=bm(2)’)
然后发现程序 有问题,不能执行!方程很简单,我只是举例说明我遇到的问题,mx,bm为上面的程序 解出来的方程组,我想在下面的程序中引用,然后再进行求解,希望高手指点下!!!
先谢过啦!
非常感谢1 楼,你无意之中给我 一个解决超越方程的方法,这个问题我在解最大爬坡度时遇到过, 看啦你的回答 无疑多一种思路!
同时感谢2楼 你的正解 !(弱弱的问一下,solve的语法我都看啦,怎么没发现还有这个语句,但是他 的确能解决我的问题)!!!
多谢!!!

先不管你的方程,因为我也没大看懂,知说关于solve
例子1
syms x;
solve(x^2 - 1)
solve('x^2 + 4*x + 1')

ans =
1
-1

ans =
3^(1/2) - 2
- 3^(1/2) - 2
例子2
the right side of an equation is not zero, specify the equation as a string:
如果等式右边不是0,指定这个等式用字符串
syms x;
solve('x^4 + 1 = 2*x^2 - 1')

The solver returns the symbolic array of solutions:

ans =
(i + 1)^(1/2)
(1 - i)^(1/2)
-(i + 1)^(1/2)
-(1 - i)^(1/2)
例子3
To avoid ambiguities when solving equations with symbolic parameters, specify the variable for which you want to solve an equation:
为了避免解方程的时候符号参数指代不清,,怎么指代你想要的未知数
syms a b c x;
solve(a*x^2 + b*x + c, a)
solve('a*x^2 + b*x + c', 'b')

The result is:

ans =
-(c + b*x)/x^2

ans =
-(a*x^2 + c)/x

例子4
When solving a system of equations, use one output argument to return the solutions in the form of a structure array:
当解这种方程的时候只用一个输出参数的情况
syms x y;
S = solve('x + y = 1','x - 11*y = 5')

S =
x: [1x1 sym]
y: [1x1 sym]

To display the solutions, access the elements of the structure array S:

S = [S.x S.y]

S =
[ 4/3, -1/3]
例子5
syms x positive;
solve('sin(x) = x^2 - 1')
解出第一个解
ans =
-0.63673265080528201088799090383828
但是可能还有别的解,因为MATLAB是指解一个解就退出求解程序
,作图判断
ezplot(sin(x), -2, 2);
hold on;
ezplot(x^2 - 1, -2, 2)
hold off

果然有第2个解,,重新设定起始点来求:
evalin(symengine, 'numeric::solve(sin(x) = x^2 - 1, x = 0..2)')

ans =
1.4096240040025962492355939705895

这里关于这个重新设定起始点,有另一种方法
[x0,y0]=ginput(2);
%在图上取两个点的坐标
用这种形式来取点,非常方便
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-06
这个语法不对
syms x y
mx1=x+3;bm2=54./y;
a=solve(['y=',char(mx1)],['x=',char(bm2)],'x','y')
a.x
a.y

a =

x: [2x1 sym]
y: [2x1 sym]

ans =

6
-9

ans =

9
-6本回答被提问者采纳