sandra
sandra

Reputation: 987

get real values from solve function in matlab

I have a function in Matlab and want to find it's points in which value of F is 0.5 (more than one point) I wrote my code as bellow : (function defined in '')

 result=solve('(1/(1+ ((x-5)/2)^(2*4)))=0.5');

but this return both real and complex x in which value of function is 0.5, I need just real numbers. how can I get real results from solve function in Matlab.

Upvotes: 0

Views: 718

Answers (1)

MeMyselfAndI
MeMyselfAndI

Reputation: 1320

The solution can be found in the documentation of solve:

result = solve('(1/(1+ ((x-5)/2)^(2*4)))=0.5', 'Real', true)

By the way, you could also get the desired real valued subset of the results by considering result(1:2). Changing the array of sym class values to an array of double values can be done with double(result), after which you can use isreal to obtain the real solutions as well.

Upvotes: 2

Related Questions