Solving equation

i am trying to solve ((a+b)^2 -2*a*b -a^2)/b^2
using inline function I am getting output, but with normally(using solve and function) either I am getting an error or output as zero(where as I must get only 1).how should I program it?? further i need to create it on Xcel. how to do that??

回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 4 月 27 日

0 投票

To get just ans=1 you need the Symbolic Math Toolbox™
syms a b
simplify(((a+b)^2 -2*a*b -a^2)/b^2)
ans =
1

3 件のコメント

Namit Chandra
Namit Chandra 2011 年 4 月 27 日
with the solution u have given is returning me this
ans =
- (2*a)/b - (a^2 - (a + b)^b)/b^2
Andrew Newell
Andrew Newell 2011 年 4 月 27 日
What do you get if you try simple instead of simplify?
Walter Roberson
Walter Roberson 2011 年 4 月 27 日
Notice the ^b in your output. It is an indication that very likely you have a typo in the equation you are requesting to be solved, or else the equation to be solved is not the one you showed to us. Another possibility is that you have given values to "a" or "b" before you reach this section of the code.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

質問済み:

2011 年 4 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by