How to get variable r recognised when inputting a matrice? eg matrix1 = [1, 0; 2/r, 1]
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Neil
el 3 de Ag. de 2022
Respondida: Steven Lord
el 3 de Ag. de 2022
Get the message:
Unrecognised function or variable 'r'.
when trying to write the matrice:
matrix1 = [1, 0; 2/r, 1]
How do I get Matlab to recognise 2/r ?
I'm a nooby to Matlab, please be kind!
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 3 de Ag. de 2022
syms r
matrix1 = [1, 0; 2/r, 1]
Or if you are going to evaluate the value for some r, a better way would be to define a symbolic function
syms matrix1(r)
matrix1(r) = [1, 0; 2/r, 1]
matrix1(2)
2 comentarios
Más respuestas (1)
Steven Lord
el 3 de Ag. de 2022
Another approach, one that doesn't require Symbolic Math Toolbox, is to create a function that you can call with a specific value of r.
M = @(r) [1, 0; 2/r, 1]
This is an anonymous function. To use this anonymous function, call it like you'd call any other function in MATLAB.
A = M(4)
B = M(2)
C = M(1)
0 comentarios
Ver también
Categorías
Más información sobre Number Theory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!