How to change the answer into decimals

5 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Polynomials 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by