Evaluating a function at complex values
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
J Schreiber
am 4 Nov. 2020
Bearbeitet: Alan Stevens
am 4 Nov. 2020
I am new to MATLAB and I am trying to evaluate a sybomlically defined function at complex values, but I get an error saying 'Array indices must be positive integers or logical values'. What should I change so that this works and outputs a complex value?
syms x
F = x^5-5*x^4-8*x^3+40*x^2-9*x+45;
P0 = 0+1i;
F(P0)
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 4 Nov. 2020
F is a symbolic expression, not a symbolic function. You need to use subs()
syms x
F = x^5-5*x^4-8*x^3+40*x^2-9*x+45;
P0 = 0+1i;
subs(F, x, P0)
Following define F as symbolic function
syms x
F(x) = x^5-5*x^4-8*x^3+40*x^2-9*x+45;
P0 = 0+1i;
F(P0)
0 Kommentare
Weitere Antworten (1)
Alan Stevens
am 4 Nov. 2020
Bearbeitet: Alan Stevens
am 4 Nov. 2020
You need to make sure F is a function. For your particular function you don't need it to be symbolic:
>> F =@(x) x^5-5*x^4-8*x^3+40*x^2-9*x+45;
>> P0 = 2+0.5*i;
>> F(P0)
ans =
87.3125 -11.4688i
0 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Variables, Expressions, Functions, and Preferences 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!