1. Nov 21, 2005

Brandt

Hi Guys,
I just have a simple question about Matlab. When solving a quadratic equation two answers will be produced. If one is Negative what command can I use in Matlab to disregard it and continue further calculations with just the positive one?

Thanks.

2. Nov 22, 2005

Tide

The result should be returned as an array and you can access individual elements to determine the sign of each one. Write a subroutine/function to test the elements of the matrix and return a matrix with only postive elements.

3. Nov 29, 2005

Brandt

Thanks Tide. I tried what you said, writing a little if else routine to give me only the positive answer, put that led to another problem. It wouldnt work because the answer of the quadratic is a sym object and the routine will only work for an array. Do you know how i can convert it or find a way around this? I thought I would send you part of the code that i wrote:

>> h = 500;% Input Value
>> V = 55;% Input Value
>> syms t;
>> T = @(h,V)((V*sin(0))*t - 0.5*9.8*t^2 + h );
>> T(h,V);
>> T = ans;
>> solve(T);
>> T = ans
>> if ans(1,1)> 0 & ans(2,1)>0
>> T = ans
>> elseif ans(1,1)< 0 & ans(2,1)>0
>> T = ans(2,1)
>> else T= ans(1,1)
>> end

Let me know what you think. Thanks for the help.

4. Nov 30, 2005

Tide

Brandt,

I don't have current access to MatLab so I can't fiddle with it to try and resolve the issue. I do have a clone with sparse documentation but I'll see if I can dig anything up. Any current ML users - feel free to jump in!

5. Dec 5, 2005

Brandt

Oh ok, well thanks Tide. I did find a way to convert from into an actual number, that is with the double command. however, this proved inconsequential as Matlab refuses to use this programming block when I call it up as a function giving me an error message that I have used the variable t (in code above) as a command/function. It seems to ignore the fact that I defined it as an symbolic object before. Funnily enough, when I run the routine on its own It works fine. If anybody has any ideas please let me know. Thanks.