From: George Scholz on
Hi guys, I've just started an engineering project in 2nd year, and have also started matlab recently.

I'm trying to make macaulay brackets work with matlab, and apparently doing the max(x-start,0) is the way to do that.

However, when I try to do this I get an unspecified error. I'm sure it's a basic thing I've done wrong, but as I've said I'm very new to this.

Anyway here is my code:

function shear_max_vertical(x)
shear=0-4748.1*(max(x-0,0))^0+8133.9*(max(x-0.55,0))^0-515.2*(max(x-1.05,0))^0-2870.6*(max(x-1.32,0))^0;
plot(x,shear)
end

Basically what I want to be able to do is add the vector x in steps of 0.01 from 0 to 1.32 (ie: 0:0.01:1.32)
I then want this to find the shear using the equation above for each step, then plot them against each other.


The way the brackets work are such that, for example, max(x-0.55,0) means that when x is less or equal to 0.55, the value will be 0, so that term will not be included, and after that it will. I have then powered them to the power 0 so that it essentially means the term is either on eg if x=1: max(x-0.55,0)^0 would take the largest of the two, being 0.45, then turn it into 1, thereby turning that term on.

What have I done wrong with the code?

Thanks so much for any help!
From: Steven Lord on

"George Scholz" <gks21(a)bath.ac.uk> wrote in message
news:hbkqg6$mf5$1(a)fred.mathworks.com...
> Hi guys, I've just started an engineering project in 2nd year, and have
> also started matlab recently.
>
> I'm trying to make macaulay brackets work with matlab, and apparently
> doing the max(x-start,0) is the way to do that.
>
> However, when I try to do this I get an unspecified error. I'm sure it's a
> basic thing I've done wrong, but as I've said I'm very new to this.

Usually when you indicate that a piece of code threw an error, you should
include the error message exactly as it was displayed in the Command Window,
as that can be very useful in determining exactly what went wrong.

> Anyway here is my code:
>
> function shear_max_vertical(x)
> shear=0-4748.1*(max(x-0,0))^0+8133.9*(max(x-0.55,0))^0-515.2*(max(x-1.05,0))^0-2870.6*(max(x-1.32,0))^0;
> plot(x,shear)
> end
>
> Basically what I want to be able to do is add the vector x in steps of
> 0.01 from 0 to 1.32 (ie: 0:0.01:1.32)
> I then want this to find the shear using the equation above for each step,
> then plot them against each other.
>
>
> The way the brackets work are such that, for example, max(x-0.55,0) means
> that when x is less or equal to 0.55, the value will be 0, so that term
> will not be included, and after that it will. I have then powered them to
> the power 0 so that it essentially means the term is either on eg if x=1:
> max(x-0.55,0)^0 would take the largest of the two, being 0.45, then turn
> it into 1, thereby turning that term on.

This isn't going to do what you want. You should just replace all your
"max(foo, 0)^0" calls with 1, as 0^0 is defined to be 1.

http://en.wikipedia.org/wiki/0%5E0#Zero_to_the_zero_power

Depending on what you expect this function to receive (scalar, vector,
matrix, etc.) and what specifically you're looking for, I _think_ you may be
able to use BSXFUN, FIND, or HISTC to do what you want with more generality.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ