Trusted by Students Everywhere
Why Choose Us?
0% AI Guarantee

Human-written only.

24/7 Support

Anytime, anywhere.

Plagiarism Free

100% Original.

Expert Tutors

Masters & PhDs.

100% Confidential

Your privacy matters.

On-Time Delivery

Never miss a deadline.

Darryl Yong (he/him) Today at 9:15 PM Hint for everyone about ode45: ode45 numerically calculates solutions to a differential equation and it uses adaptive step-sizes for the independent variable

Writing May 25, 2022

Darryl Yong (he/him) Today at 9:15 PM Hint for everyone about ode45: ode45 numerically calculates solutions to a differential equation and it uses adaptive step-sizes for the independent variable. Basically, that means if you do [x, v2] = ode45(@ode, [0, 500], 0) you are going to get a vector of x values that you don't get to control. You can calculate the maximum squared velocity using max(v2), but those velocities correspond to those x-values that you don't get to control. This might cause some issues down the road for fminsearch/fmincon. I recommend instead being more consistent in where you calculate the squared velocities via desolution = ode45(@ode, [0, 500, 0) v2 = deval(desolution, linspace(0, 500, 100)) This evaluates the squared velocity at the x coordinates ranging from 0 to 500 with 100 equally spaced points. (You can change this to whatever you like here, it's just an example.) It might not seem like a huge difference, but because fmincon/fminsearch are very sensitive to the values of your objective function, a small change like this can have an effect. Hope that helps.

Expert Solution

velsquared = [0];

for i = (2:length(xcoords))

dy = ycoords(i) - ycoords(i-1);

dx = xcoords(i) - xcoords(i-1);

dv2 = (M * 9.81 * sin(-atan(dy/dx)) - 1/2 * 1.2 * 0.05 * M^(2/3) * velsquared(end)) * 2 * sqrt(1 + (dy/dx)^2) / M * dx;

velsquared = [velsquared velsquared(end) + dv2];

end

 

with these new lines of code:

interpy = spline(xcoords, ycoords);

interpyder = fnder(interpy,1);

desolution = ode45(@(x,v2) (M * 9.81 * sin(-atan(ppval(interpyder,x))) - 1/2 * 1.2 * 0.05 * M^(2/3) * v2) * 2 * sqrt(1 + (ppval(interpyder,x))^2) / M, [0, 500], 0);

 

velsquared = deval(desolution, linspace(0, 500, length(xcoords)));

 

For some reason, running fmincon does not give the same result for the optimal parameters as the original code, even though I checked by hand that the resulting velsquared vector is the same for both methods up to differences of ~1%. I'm not sure if there's anything I can do about that, but if I think of something I will let you know.

Please view explanation and answer below.

After a bit of tinkering, I found a trick to make it work: In the minutility file, use this code instead:

options = optimoptions('fmincon', 'Algorithm','interior-point','DiffMinChange',1e-2);

myans = fmincon(@getUtility, [35 50000], [], [], [], [], [10 0], [40 50000], [], options);

 

The extra options will improve convergence. Hope that helps :)

Hey again, I had a chance to look into that extra credit problem - I found that constraining to 2.5 instead of 5.0 led to an optimal configuration of 31.4 m and 50,000 N. (The code itself didn't have to change much - just the numbers in defining exitVelocityErrorCount were altered from 5 to 2.5.

Archived Solution
Unlocked Solution

You have full access to this solution. To save a copy with all formatting and attachments, use the button below.

Already a member? Sign In
Important Note: This solution is from our archive and has been purchased by others. Submitting it as-is may trigger plagiarism detection. Use it for reference only.

For ready-to-submit work, please order a fresh solution below.

Or get 100% fresh solution
Get Custom Quote
Secure Payment