# Cannot simplify a result

조회 수: 6 (최근 30일)
Geovane Gomes 2022년 3월 26일
댓글: Geovane Gomes 2022년 3월 26일
Hi all,
I am trying to simplify at most the result of Td, but the maximum I get is (3*pi*39270^(1/2))/1666. When I put this result in command window it shows 1.1211, as I want, but not direct from the script.
I've already tried using simplify/simplifyFraction but didn't work.
Trust all clear
Thanks
clc
clear all
syms rho x L E w t csi
A=w*t;
I=(t*w^3)/12;
phi=(3*x^2)/(2*L^2) - x^3/(2*L^3);
phi1=diff(phi,x);
phi2=diff(phi,x,2);
Meq=int(rho*A*phi^2,x,0,L);
Keq=int(E*I*phi2^2,x,0,L);
ohmega=sqrt(Keq/Meq);
Td=simplify((subs(Td,[E,w,L,rho,csi],[72e9,1,30,3000,0.02])))
Td =

댓글을 달려면 로그인하십시오.

### 채택된 답변

Cris LaPierre 2022년 3월 26일
Symbolic results are exact. If you want a decimal approximation, convert the symbolic value to a double.
syms rho x L E w t csi
A=w*t;
I=(t*w^3)/12;
phi=(3*x^2)/(2*L^2) - x^3/(2*L^3);
phi1=diff(phi,x);
phi2=diff(phi,x,2);
Meq=int(rho*A*phi^2,x,0,L);
Keq=int(E*I*phi2^2,x,0,L);
ohmega=sqrt(Keq/Meq);
Td=simplify((subs(Td,[E,w,L,rho,csi],[72e9,1,30,3000,0.02])))
Td =
% Convert Td to a double
Td_num = double(Td)
Td_num = 1.1211

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

John D'Errico 2022년 3월 26일
편집: John D'Errico 2022년 3월 26일
You got a "numerical" result. But because the result is symbolic, that is the symbolic result. pi, and square roots are as you would expect in such a result. Then you tried to simplify them, but they were already in a maximally simple form as a symbolic result. It was not simplification you weree looking for, but to express them as floating point numbers.
You can turn them into actual floating point numbers using double. Or you can use vpa, to turn them into floaing point numbers, but as a symbolic form of a floating point number.
For example, you got this result:
X = str2sym('(3*pi*39270^(1/2))/1666')
X =
As far as the symbolic toolbox is concerned, the job is done. That was fun, right? But you wanted real numbers. DOUBLE or VPA will do the job.
double(X)
ans = 1.1211
vpa(X)
ans =
1.1210541248532242623574383591283
So double turns it into a double precision number, VPA turns it into a floating point number, but still in symbolic form. Here with 32 significant digits as the default for VPA, so roughly twice what a double gives you. (Remember that a double only displayed 5 digits there, but the number is stored as full double precision.)
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Geovane Gomes 2022년 3월 26일
Thanks!
Great explanation!
And yes. That was really fun

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by