[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 103 KB, 570x558, angrygorilla.jpg [View same] [iqdb] [saucenao] [google]
7153431 No.7153431 [Reply] [Original]

I'm having trouble figuring out how to write this function to use with Euler's method in matlab, could really use some help if anyone can figure out why the fuck it gives me pic related when trying to solve with ODE45:


function y_ut = bjODE(t,dy)

W = 686; %gravitationalforce(N)
c = 0.227; %constant for air resistance(kg/m)
D = sign(dy(2))*c*dy(2)^2; %air resistance
B = 10*(dy(1) - 150); %force affecting jumper if x(t)>150m
m = 70; %JumperWeight(kg)

if dy(1) < 150
F = (W-D);
else
F = (W-D-B);
end

y_ut = [ F/m;
dy(2) + dy(1)
dy(3) + dy(2)];


Original ODE's are:
x''(t) = (686 - 0.227*x'(t)^(2)) / 70
and when x>150:
x''(t) = (686 - 0.227*x'(t)^(2)-10(x(t) - 150)) / 70

>> No.7153497

>>7153431

I'm drunk and just guessing, but doesn't the ODE family only solve first-order diff-eqs?

Maybe you should try to split that second-order into a system of first-orders.

>> No.7153537

>>7153497

Also, anonymous functions FTW.

Unless you're going to use this many times for different things, consider defining your constants and conditional statement above in your main code and defining the system of diff-eqs inline like so
[t,y] = ode45( @(t,y) [eq1;eq2], tspan, y0 )

I think it's snazzier... and I have absolutely no idea what I'm talking about...

>> No.7154146

If anyone here is good at matlab, could you tell me how to get the difference in brightness for two images?

>> No.7155323

>>7153431
Do you study in Sweden by any chance? I literally had classes on this on tuesday and today.

>> No.7156695

>>7155323
Yes, (gissar på att du precis börjat bervet på UU? Pluggade förra perioden men har kvar denna uppgift :( )

>> No.7156737

>>7153431
I can't really see what you did, your code is too ugly, which dy is your dummy variable for x exactly? ODE45 isn't magic, also you don't need those if statements, just do for example

F = @(dy(1)) (W - D)*(dy(1) < 150.0) + (W-D-B)*(dy(1) > 150.0)

only with the entire function.

Also don't rely on ODE45, just write your own runge-kutta routine, it takes 20 minutes and then you have a function where you know exactly what can go wrong for the rest of your life. RK45 variable step routines are also pretty simple, you can write one in an afternoon or a weekend depending how good you are at coding simple algorithms.