Multiplication matrix with strings

조회 수: 10 (최근 30일)
PANAGIOTIS
PANAGIOTIS 2023년 2월 21일
편집: Star Strider 2023년 2월 21일
how can i multiply matrices with strings, for example [k1-2*m,-k2;-k2,k2]*[1,2;4,6]
  댓글 수: 1
Luca Ferro
Luca Ferro 2023년 2월 21일
편집: Luca Ferro 2023년 2월 21일
syms k1 k2 m
mult=[k1-2*m,-k2;-k2,k2].*[1,2;4,6]
You need to create symbolic variables before using them.
I'm not sure if you just want to multiply them or element wise multiply them. I decided in my code to element wise multiply them

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

답변 (1개)

Star Strider
Star Strider 2023년 2월 21일
편집: Star Strider 2023년 2월 21일
Perhaps this —
syms k1 k2 m
M = [k1-2*m,-k2;-k2,k2]*[1,2;4,6] % Symbolic Expression
M = 
Mfcn = matlabFunction(M) % Create Numeric Function From It
Mfcn = function_handle with value:
@(k1,k2,m)reshape([k1-k2.*4.0-m.*2.0,k2.*3.0,k1.*2.0-k2.*6.0-m.*4.0,k2.*4.0],[2,2])
Result = Mfcn(10,20,30)
Result = 2×2
-130 -220 60 80
The ‘M’ expression will work in a symbolic context, and ‘Mfcn’ can be used in non-symbolic (numeric) MATLAB code.
EDIT — Added ‘Result’ as a demonstration.
.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by