wolfram alpha operation in matlab

7 ビュー (過去 30 日間)
fima v
fima v 2017 年 3 月 12 日
コメント済み: Walter Roberson 2017 年 3 月 12 日
how can i enter an expression and get the value of the variable that creates it?(like in wolfram alpha attached photo)
Thanks

採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 12 日
Alternately,
syms x
solve(1.08393 == (1+x)/(1-x), x)
  2 件のコメント
fima v
fima v 2017 年 3 月 12 日
is there a way do it on a whole vector instead of 1.08393' i get an error
Thanks
Warning: The solutions are valid under the following conditions: z - 1 ~= 0 & z == 186134054074199/2437933867759447 & z == 2374416420871865/11381615675612857 & z == 3937943466562597/8441543093933093 & z == 6495012520173245/7057962473594557. To include parameters and conditions in the solution, specify the 'ReturnConditions' option.
Walter Roberson
Walter Roberson 2017 年 3 月 12 日
John D'Errico's solution (k - 1)./(k + 1) looks fine.

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

その他の回答 (2 件)

Stephen23
Stephen23 2017 年 3 月 12 日
>> fun = @(x)(1+x)/(1-x)-1.08393;
>> fzero(fun,0)
ans =
0.0402748652785842

John D'Errico
John D'Errico 2017 年 3 月 12 日
編集済み: John D'Errico 2017 年 3 月 12 日
It seems silly to throw a computer at something that is done using pencil and paper. I think sometimes we forget how to think, allowing the computer to do that for us. That can get to be a habit, and once we lose a skill, it won't be grown again easily.
k = (1+x)/(1-x)
First, look at the plot that is most easily drawn using ezplot:
ezplot(@(x) (1+x)./(1-x))
grid on
Here we see that if we were to swap the axes, trying to produce x as function of k, we would still have a hyperbolic form.
Quick pencil and paper shows (as long as x is not 1, in which case there is no solution anyway):
x = (k-1)/(k+1)
Here we see that k may never be -1 either, in which case no solution could have existed since we would have needed to divide by zero. As I suggested, the result should again have a clearly hyperbolic form, which it does. Always check your results against your knowledge of the process. Any computation, whether done using paper or computer, should always be checked for sanity.
In MATLAB, for vector or array k, the solution is now trivial.
x_k = @(k) (k-1)./(k+1);
x_k(0:0.25:2)
ans =
-1 -0.6 -0.33333 -0.14286 0 0.11111 0.2 0.27273 0.33333
x_k(1.08393)
ans =
0.040275
format long g
x_k(1.08393)
ans =
0.0402748652785842
Note the use of the ./ operator.

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by