Could I use a function of x as input like this ( fun = input(' Function of x = ');) and then when I run the program insert a function of x ?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Roger Vegeta
am 27 Jul. 2016
Beantwortet: James Tursa
am 27 Jul. 2016
Could you give me an example when the input is a function of x rather than a numerical term?
0 Kommentare
Akzeptierte Antwort
James Tursa
am 27 Jul. 2016
E.g., input your function as a MATLAB syntactically correct string, then use the str2func function to form a function handle. E.g.,
>> s = input(' Function of x = ','s')
Function of x = 2*x+1
s =
2*x+1
>> fun = str2func(['@(x)' s])
fun =
@(x)2*x+1
>> fun(1)
ans =
3
>> fun(2)
ans =
5
>> fun(3)
ans =
7
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!