solve equation and return a column vector array which has lower root instead of lower and upper root
1 view (last 30 days)
Show older comments
Hi guys,
I have an equation which I want to solve for but i'm trying to make it return a column vector of solutions. Say if the input y is a column vector array i.e. [100,200,300,400,500,600,700] I want the solve function to return a column vector as well. The problem lies with equation which solves for two roots and I was hoping to get the lower root i.e.
sol=solve(eqn==0,y);
sol(1);
However it ruins the 'size' of the matrix and i was wondering if anyone knows how to selectively obtain all the lower roots i.e. sol(1) if the solution has 2 solutions.
Any hints would be appreciated.
0 Comments
Accepted Answer
Star Strider
on 28 Jun 2015
You don’t give enough information to provide a specific solution.
If you are solving for the zeros of a one-variable function, it might be most appropriate to use matlabFunction to create an anonymous function out of ‘eqn’, and then use fzero, fsolve, or a related function to find the roots. Depending on what it returns, you can choose the root you want to keep.
Use a loop to define each element of your [1:7]*100 vector in ‘eqn’, and solve it in each iteration.
2 Comments
Star Strider
on 28 Jun 2015
My pleasure.
No worries — it just makes it easier to provide a specific Answer.
If you get stuck, please post the relevant parts of the code you wrote. If it threw any errors, post the complete red text of any errors it threw. If it ran but didn’t do what you wanted, describe what it did you didn’t want it to, and what it didn’t do that you wanted it to.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!