How to change the answer into decimals

15 ビュー (過去 30 日間)
Faris Sulam
Faris Sulam 2021 年 1 月 25 日
編集済み: VBBV 2021 年 1 月 25 日
Hi all,
I wanted to ask about my result here. Usually it is in decimals but when i used poly2sym here it turned into fractions. How can I change it back to decimals? Thanks in advance
  2 件のコメント
Birdman
Birdman 2021 年 1 月 25 日
Can you share your entire code? It is hard to tell what you tried to do here.
Faris Sulam
Faris Sulam 2021 年 1 月 25 日
So i was basically trying to convert the answer of the folloing code into a polynomial form:
function [ p ] = UDPolyReg( x,y )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
%y=[0 3 4.5 5.8 5.9 5.8 6.2 7.4 9.6 15.6 20.7 26.7 31.1 35.6 39.3 41.5]
n=length(x);
m=4;
for i=1:2*m
xsum(i)=sum(x.^(i));
end
a(1,1)=n
b(1,1)=sum(y)
for j=2:m+1
a(1,j)=xsum(j-1);
end
for i=2:m+1
for j=1:m+1
a(i,j)=xsum(j+i-2);
end
b(i,1)=sum(x.^(i-1).*y);
end
p=(a\b)'
for i=1:m+1
FuncVal(i)=p(m+2-i);
end
Vstrain=0:0.1:6;
stressfit=polyval(FuncVal,Vstrain);
plot(x,y,'ro',Vstrain, stressfit)
xlabel('Strain')
ylabel('Stress')
end

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

採用された回答

VBBV
VBBV 2021 年 1 月 25 日
編集済み: VBBV 2021 年 1 月 25 日
poly2sym converts numeric vector to vector of symbolic equation and by default it uses the variable x. The values in vector are treated as coefficient of symbolic polynomial in x.
  1 件のコメント
VBBV
VBBV 2021 年 1 月 25 日
編集済み: VBBV 2021 年 1 月 25 日
In your case vector has 5 values. So it results in polynomial in 4th power. MATLAB converted the numeric values to fractions and expressed in form of polynomial.
Use sym2poly to convert back to numeric vector.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by