Why does the solve function give me matrix instead of a number ?

4 ビュー (過去 30 日間)
Eyrún Guðmundsdóttir
Eyrún Guðmundsdóttir 2019 年 2 月 22 日
編集済み: John D'Errico 2019 年 2 月 22 日
Im using the solve command and it gives me 3x1 matrix instead of a number so I get error because its not the same size on the left and right. Im using this
syms h;
g= subs(f, [x1,x2], [X1(i)+s(1)*h, X2(i)+h*s(2)]);
dg_dh=diff(g,h);
h = solve(dg_dh,h);
and g and dg_dh are both just numbers but my h is 3x1 matrix but I need it to be a number, can anyone see what Im doing wrong here?
This is what I get for h
root(z^3 - (35175*z^2)/60236 + (22211250*z)/226773481 - 10890625/1814187848, z, 1)
root(z^3 - (35175*z^2)/60236 + (22211250*z)/226773481 - 10890625/1814187848, z, 2)
root(z^3 - (35175*z^2)/60236 + (22211250*z)/226773481 - 10890625/1814187848, z, 3)
  1 件のコメント
Torsten
Torsten 2019 年 2 月 22 日
Maybe dg_dh has three roots instead of only one ?

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

回答 (1 件)

John D'Errico
John D'Errico 2019 年 2 月 22 日
編集済み: John D'Errico 2019 年 2 月 22 日
You get 3 values, because there were 3 solutions found.
You can convert them to numbers using vpa.
syms z
vpa([root(z^3 - (35175*z^2)/60236 + (22211250*z)/226773481 - 10890625/1814187848, z, 1)
root(z^3 - (35175*z^2)/60236 + (22211250*z)/226773481 - 10890625/1814187848, z, 2)
root(z^3 - (35175*z^2)/60236 + (22211250*z)/226773481 - 10890625/1814187848, z, 3)],15)
ans =
0.113779972551139 - 0.0624336484642866i
0.113779972551139 + 0.0624336484642866i
0.356393172634623
So we see two complex roots and one real root.
You asked for a solution, but solve cannot know which solution you might wish to see.

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by