Matlab: need to enter "w(x)=(wmax*e^(-x/α)) (cos(x/α) + sin (x/α)"

fraffi

New member
Joined
Jun 7, 2018
Messages
3
Matlab: need to enter "w(x)=(wmax*e^(-x/α)) (cos(x/α) + sin (x/α)"

Hi guys, first of all I am new so thanks for your help in advance! I hope this is the right place for my problem, also if it is not a forum for matlab but maybe some of you used it already.
I have to put this into matlab:

w(x)=(wmax*e^(-x/α)) (cos(x/α) + sin (x/α)

I can put values for x and alpha
The wmax at x=0 is equal to V/(2
Δϱgα)

I am starting using matlab in these months so I am sorry if I did some rough errors but I need to improve very soon :)

I first tried to write this:

function w = pippo (x, alpha)
w = (((max(w))*(exp(-x/alpha)))*(cos(x/alpha)+sin(x/alpha)))
end

but of course it says that the max(w) might be used before it is defined.
I also did another couple of attempts using the V/(2Δϱgα) but nothing actually improved the situation.

Thank you in advance.



 
Hi guys, first of all I am new so thanks for your help in advance! I hope this is the right place for my problem, also if it is not a forum for matlab but maybe some of you used it already.
I have to put this into matlab:

w(x)=(wmax*e^(-x/α)) (cos(x/α) + sin (x/α)

I can put values for x and alpha
The wmax at x=0 is equal to V/(2
Δϱgα)

I am starting using matlab in these months so I am sorry if I did some rough errors but I need to improve very soon :)

I first tried to write this:

function w = pippo (x, alpha)
w = (((max(w))*(exp(-x/alpha)))*(cos(x/alpha)+sin(x/alpha)))
end

but of course it says that the max(w) might be used before it is defined.
I also did another couple of attempts using the V/(2Δϱgα) but nothing actually improved the situation.

Thank you in advance.



Yes, *of course* wmax has to be a constant that *you* define. You can't compute it as the maximum of an as-yet non-existent array! That's circular.

I hope you understand why this is: it isn't just a coding error. It's a *logical* error: it actually makes no sense to say w = max(w)*blah in the definition of w.

The version you wrote where wmax was a constant (V/(2Δϱgα)) should have worked fine, so if it didn't, there is a bug in your code. You should post that version of the code so that we can try to see where you might be going wrong.
 
Yes, *of course* wmax has to be a constant that *you* define. You can't compute it as the maximum of an as-yet non-existent array! That's circular.

I hope you understand why this is: it isn't just a coding error. It's a *logical* error: it actually makes no sense to say w = max(w)*blah in the definition of w.

The version you wrote where wmax was a constant (V/(2Δϱgα)) should have worked fine, so if it didn't, there is a bug in your code. You should post that version of the code so that we can try to see where you might be going wrong.

Hey, first of all thanks for replying.
Yes, actually it "kinda" worked like this:


function w = cetto3(x,alpha )
V =100;
rho=600;
g=9.8;
w_max = V/(2*(rho*g*alpha)) ;
w = ( w_max*(exp(-x./alpha)).*(cos(x./alpha)+sin(x./alpha)))
end

this worked (I mean it did not create error messages) and I put these values in the command window :

alpha= 100; (I changed alpha with several values from 9000 to 0)
g=9.8;
rho=600
V=100;
x= [0:10:2000]

The only thing that actually creates problems now to me is that I know that when I plot (x,w), the graphs I obtain are totally wrong.

I know the shape that this should have and this shape should be mostly quite constant, no matter how much I change the alpha value. But unfortunately it changes a lot when I try different values of alpha.
It shows totally different kind of curves changing alpha.

I am struggling finding the problem.

(Thank you j-astron) :)
 
Matlab: need to enter "w(x)=(wmax*e^(-x/α)) (cos(x/α) + sin (x/α)"

Yes, *of course* wmax has to be a constant that *you* define. You can't compute it as the maximum of an as-yet non-existent array! That's circular.

I hope you understand why this is: it isn't just a coding error. It's a *logical* error: it actually makes no sense to say w = max(w)*blah in the definition of w.

The version you wrote where wmax was a constant (V/(2Δϱgα)) should have worked fine, so if it didn't, there is a bug in your code. You should post that version of the code so that we can try to see where you might be going wrong.

Hi, first of all many thanks for your reply.
Yes I actually tried with this code:

function w = cetto3(x,alpha )
V =100;
rho=600;
g=9.8;
w_max = V/(2*(rho*g*alpha)) ; % formula w max
w = ( w_max*(exp(-x./alpha)).*(cos(x./alpha)+sin(x./alpha)))
end

In the command window then I put these values:
alpha=100;
g=9.8;
rho=600;
V=100;
x= [0:10:2000]

The only thing that now creates problems to me is that changing values of alpha for instance from 9000 to 0 I obtain non physically correct curves when plotting.

It seems like the code does not reflect the equation that usually gives only one very peculiar curve that is always quite the same,even when changing alpha values that much.
w(x)=(wmax*e^(-x/α)) (cos(x/α) + sin (x/α)

I don't know if you can suggest me something in this.

Cheers
 
Top