matlab的字符运算的问题。

由于所求函数f的表达式里含有很多字符常量sr se pr k theta pe w,只有pr和sr是未知的,现在求f最大值时的pr和sr。我觉得手算比较麻烦,而且容易出错,所以想借用matlab的字符运算功能,但是下面的代码运行出的结果是
>> lianxi
y1 =
- sr - ((k - theta)/theta + 1)*(w - (pe - se - k*sr + sr*theta + k*se*theta)/theta) - ((k - theta)*(sr - (pe - se - k*sr + sr*theta + k*se*theta)/theta + k*se + 1))/theta
Warning: Explicit solution could not be found.
> In solve at 169
In lianxi at 6
y1_sr =
[ empty sym ]
我的代码:
syms sr se pr k theta pe w;
pr=(theta*sr-k*sr-se+k*theta*se+pe)/theta;
qr=1+sr+k*se-pr;
f=(pr-w)*qr-sr^2/2;
f
y1=diff(f,sr)
y1_sr=solve('y1=0','sr')
我的问题:1我代码的错误在哪儿呢?2听人说含有字符函数求解里用matlab不太方便,还想问问各位求解这类的问题用matlab合适吗?

 採用された回答

cemofo
cemofo 2022 年 11 月 17 日

0 投票

syms sr se pr k theta pe w;
pr=(theta*sr-k*sr-se+k*theta*se+pe)/theta;
qr=1+sr+k*se-pr;
f=(pr-w)*qr-sr^2/2;
f
y1=diff(f,sr)
y1_sr=solve(y1==0,sr)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange编程 についてさらに検索

タグ

質問済み:

2022 年 11 月 17 日

回答済み:

2022 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!