How to assign a symbolic matrix to another new matrix?

조회 수: 12 (최근 30일)
Mehdi
Mehdi 2022년 9월 13일
편집: John D'Errico 2022년 9월 13일
clc
clear
syms t
ddq=zeros(4,11);%can not be deleted
ddq(1:4, 1)=[sin(25*t); 55*sin(25*t);65*sin(25*t);0]
Unable to perform assignment because value of type 'sym' is not convertible to 'double'.

Caused by:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.

답변 (1개)

John D'Errico
John D'Errico 2022년 9월 13일
편집: John D'Errico 2022년 9월 13일
You are NOT assigning a symbolic matrix to another "new" matrix, but you are instead trying to stuff symbolic elements into an existing double precision array, replacing only some of the existing elements. Do you see the difference?
A double precision array can contain only double precision numbers.
What exactly you are trying to do, and why you are trying to do this, I cannot know. Why it is that you think the array ddq cannot be overwritten or deleted, I do not know.
  댓글 수: 2
Mehdi
Mehdi 2022년 9월 13일
This is because RHS matrix sometimes (not always) have some symbolic elements that must be replaced at left numeric matrix. Suggest simple way to do this.(forget why this problem appeared since it needs long explaination.
John D'Errico
John D'Errico 2022년 9월 13일
Are you asking for a way to do what cannot be done? I'd then suggest magic.
Seriously, if the matrix MUST remain as it is, as a double precision matrix, then you CANNOT insert symbolic elements.
If you are willing to modify the matrix, then you can recast it as a symbolic matrix. Then you can then insert symbolic elements. For example:
M = magic(3)
M = 3×3
8 1 6 3 5 7 4 9 2
A matrix of doubles.
First, recast it as symbolic.
M = sym(M)
M = 
syms t
M(2,2) = t + 2
M = 
At this point however, the entire matrix is symbolic. It is no longer the double precision matrix you started with, and some computations may become exceedingly CPU intensive, or they may become completely impossible, if some piece of code you use does not allow symbolic matrices.

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

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by