How can I select between two solutions?

2 vues (au cours des 30 derniers jours)
Fromeros
Fromeros le 7 Juil 2011
Hello everyone,
I've been searching a solution for this problem but I haven't found anything that fits with it. I have the following equation:
dx=(y-x)(C1·y+C2)
I know the values of x, dx, c1 and c2 for 100 steps (x and dx are(100x1)vectors and c1 and c2 constants), so I solve the equation and I substitute those values, but this equation has two solutions for 'y'. I need the solution bounded by 0 and 1. How can I make Matlab to choose the solution I need? This is the code I use to get the two solutions:
sol= solve('dx=(y-x)*(y*C1+C2)')
for i=1:N
dx=ACT_dot(i,1); x=ACT(i1,1) % Set the dx and x values
y_sol(i,1:2)=subs(sol)
end
As you can see 'y_sol' is a (Nx2) matrix where I store the two values. How can I make to chose the right value in each row?
Thanks for your your attention. Best Regards

Réponses (1)

Ivan van der Kroon
Ivan van der Kroon le 7 Juil 2011
This is a standard quadratic formula, put it in the form
a*y^2+b*y+c=0
and the solutions are
y1=(-b+sqrt(b^2-4*a*c))/(2*a)
y2=(-b-sqrt(b^2-4*a*c))/(2*a)
now that you have both solutions, use operations like
y=(y>=0)*(y<=1)*y;
but you probably have some continuity requirements that you want to implement. If you want to do it quickly for only 100 points I would suggest a for-loop with if-statements.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by