How do I define a variable without assigning it a value?
Mostra commenti meno recenti
I just want to define a variable, f without assigning any values to it so I can use it in an equation.
3 Commenti
James Tursa
il 16 Giu 2016
Modificato: James Tursa
il 16 Giu 2016
Do you mean symbolically? E.g.,
syms f
Or maybe you mean an anonymous function? E.g.
myfunction = @(f)f+3
João Santos
il 12 Dic 2021
without syms, whats the best option?
Image Analyst
il 12 Dic 2021
@João Santos, see Star's answer below.
Risposta accettata
Più risposte (5)
Lucas Hilden
il 22 Gen 2020
4 voti
have no clue
2 Commenti
Allison Noe
il 12 Nov 2020
me too
James Tursa
il 12 Nov 2020
MATLAB is a dynamically typed language. You create the variable by assigning it a value. You don't need to create or type it ahead of time like you do in compiled languages such as C/C++.
Hoang Truong
il 19 Mar 2023
2 voti
syms theta;
R=[cos(theta) sin(theta)];
>> R
R = [cos(theta), sin(theta)]
Azzi Abdelmalek
il 16 Giu 2016
1 voto
Walter Roberson
il 22 Gen 2020
0 voti
You can use James' File Exchange contribution https://www.mathworks.com/matlabcentral/fileexchange/31362-uninit-create-an-uninitialized-variable-like-zeros-but-faster to create an uninitialized array. The initial contents of the variable will be whatever happened to be in memory,
Walter Roberson
il 12 Dic 2021
0 voti
If you are trying to set up an optimization problem, sometimes it is easier to do it by expressing relationships between variables. You might be able to take advantage of Problem Based Optimization
In some cases, equations that you might not think of normally as being optimizations can be rewritten: the expression A(x) == B(x) can potentially be rewritten in terms of minimizing (A(x)-B(x))^2, so if you have the Optimization Toolbox but not the Symbolic Toolbox, then this approach has some potential.
Categorie
Scopri di più su Operations on Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!