help to fix this numeric symbolic array

I need some help with the code below:
scaleFactors = [ 3.4, 2.3;
1.7, 1.9 ]
xMatSym = sym('X',[ 2, 2 ]);
xScaled = xMatSym./scaleFactors;
I am hoping to get the results shown below:
X1_1/3.4 X1_2/2.3
X2_1/1.7 X2_2/1.9
But, instead I am getting the results below instead:
(5*X1_1)/17 (10*X1_2)/23
(10*X2_1)/17 (10*X2_2)/19
I know the reasons it doesn't work. But I don't know how to fix this. Can someone help me?
Thank you so much!

댓글 수: 3

Jan
Jan 2017년 8월 12일
편집: Jan 2017년 8월 12일
I've used the "{} code" button to format the code and the numbers. Do you see that this improves the readability? Please use this by your own in the future.
What does "fixing" mean, if the current results are correct? 5*x/17 is the same as x/3.4 mathematically. Working with integer numbers is more accurate from the view point of numerics.
I've looked at doc sym: conversion techniques, but have too few experiences with the symbolic toolbox to adjust the display as wanted.
Lisa Lee
Lisa Lee 2017년 8월 12일
Hi, Jan, I am not sure what you mean about "{} code". I think that's for cell array. Mind to show what you mean to me with an example?

답변 (1개)

Karan Gill
Karan Gill 2017년 8월 12일
편집: Karan Gill 2017년 10월 17일

0 개 추천

You can't have a "numeric symbolic" array because "numeric" and "symbolic" are different data types. For your options, see https://www.mathworks.com/help/symbolic/choose-symbolic-or-numeric-arithmetic.html.
Instead, try the vpa function on your result.

댓글 수: 2

Note that vpa(xScaled) will get you output such as
[ 0.29411764705882352941176470588235*X1_1, 0.43478260869565217391304347826087*X1_2]
[ 0.58823529411764705882352941176471*X2_1, 0.52631578947368421052631578947368*X2_2]
You can also
>> vpa(xScaled,2)
ans =
[ 0.29*X1_1, 0.43*X1_2]
[ 0.59*X2_1, 0.53*X2_2]
Notice these are multiplications, not divisions, and it does matter for precision purposes how many digits you truncate to.
>> 1000/1.7
ans =
588.235294117647
>> 1000*.59
ans =
590
Karan Gill
Karan Gill 2017년 8월 13일
Yes, I do not recommend using vpa(xScaled,2) to anyone who hasn't carefully read the vpa doc :) Too much potential for confusion.

이 질문은 마감되었습니다.

질문:

2017년 8월 9일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by