solve equation and return a column vector array which has lower root instead of lower and upper root

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Star Strider
Star Strider il 28 Giu 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 Commenti
sarah
sarah il 28 Giu 2015
Thanks. I'll try that and show the specific solution if i get stuck.
Sorry for that i'll keep that in mind next time i ask a question.
Star Strider
Star Strider il 28 Giu 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by