How to assign a symbolic matrix to another new matrix?

10 views (last 30 days)
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.

Answers (1)

John D'Errico
John D'Errico on 13 Sep 2022
Edited: John D'Errico on 13 Sep 2022
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 Comments
Mehdi
Mehdi on 13 Sep 2022
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 on 13 Sep 2022
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.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!