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 CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by