Apologies and thanks for your time at the start, I only started using matlab a month ago, and pretty much made this from scratch using the internet. Also I should really stop doing all of my Matlab stuff after midnight. I am trying to approximate the distance I'll throw with a trebuchet, and decide what lengths to use for certain parts. While doing this I encountered an error in the line where I try to integrate a formula. What I suspect is that it doesn't want to integrate because it might be getting it's input as a matrix, but that's where my insights end.
clear all; close all; clcticsavedmax = 0m_weight = 0.224;m_object = 0.008;g = 9.81;Theta_launch= 3/4*pi;A = 0.0001435;rho = 1100;gamma = 88/13;d = 0.01; r_b = 0.044; r_s = 0.0059; epsilon = pi;phi_e = 3/2*pi;n_var_Theta=13;Theta = zeros(n_var_Theta,1);n_L_weight=11;L_weight = zeros(n_L_weight,1); n_L_throw=11;L_throw = zeros(n_L_throw,1);n_h_b=11;h_b = zeros(n_h_b,1);n_h_s=11;h_s = zeros(n_h_s,1);for k_var1 = [1:n_var_Theta] Theta(k_var1,1) = 1/6.*pi.*k_var1 -1/6.*pi; for k_var2 = [1:n_L_weight] L_weight(k_var2,1) = 0.01713404.*k_var2 +0.205-0.017134041; for k_var3 = [1:n_L_throw] L_throw(k_var3,1) = 0.012.*k_var3 +0.155-0.012; for k_var4 = [1:n_h_b] h_b(k_var4,1) =0.04.*k_var4 -0.04; for k_var5 = [1:n_h_s] h_s(k_var5,1) =0.04.*k_var4 -0.04; Lh_b = L_weight+h_b; L_neg_hb = h_b-L_weight; if Lh_b > 0.4 phi_b = -asin((0.4-h_b)./L_weight)+pi; end if Lh_b <= 0.4 phi_b=0.5.*pi; end if L_neg_hb < 0 phi_e = -asin(-h_b./L_weight)+pi; end if L_neg_hb >= 0 phi_e = 3/2.*pi; end Lorum = @(Theta)((-L_throw.*m_weight.*g.*cos(Theta)+ gamma.*L_weight.*m_object.*g.*cos(-gamma.*Theta+3.*pi./4-gamma.*(phi_e-phi_b)+gamma.*phi_e))./(1./4.*rho.*A.*(L_weight.^4)+1./2.*pi.*d.*rho.*(r_b.^2)+(L_weight.^2).*m_weight+gamma.*(1./4.*rho.*A.*(L_throw.^4)+1./2.*pi.*d.*rho.*(r_s.^2)+(L_throw.^2).*m_object))); Ipsum = integral( Lorum , phi_b, phi_e); omikron_b = sqrt(2.*abs(Ipsum)); omikron_s = gamma .* omikron_b; v_0 = omikron_s.*L_throw; h_s = h_b - sin(epsilon).*(r_s+r_b); h_launch = h_s + L_throw .* sin(Theta_launch); t= (-v_0.*sin(Theta_launch)-sqrt((v_0.*sin(Theta_launch)).^2+2.*g.*h_launch))./(-g); s_x = v_0.*cos(Theta_launch).*t - sin(Theta_launch).*L_throwmaxcurrentcolumn = max(s_x) %output formulas
if maxcurrentcolumn >= savedmax savedmax = maxcurrentcolumn L_weightfinal = L_weight L_throwfinal = L_throw h_bfinal = h_b h_sfinal = h_s Theta_finals = Thetaendendendendendendtoc
As my model is a bit of a mess I'll try to explain a bit of what you're seeing, and then focus on getting the integrating part to work. We're trying to do this for 5 variables, which are defined in the "for" -parts. Under the for parts there's 4 "if" parts which I don't think are working at the moment, which should define phi_e and phi_b. Running this resulted in an undefined phi_e, so it has a set value for now.
Beneath that is the part I'm having problems with.
Lorum = @(Theta)((-L_throw.*m_weight.*g.*cos(Theta)+ gamma.*L_weight.*m_object.*g.*cos(-gamma.*Theta+3.*pi./4-gamma.*(phi_e-phi_b)+gamma.*phi_e))./(1./4.*rho.*A.*(L_weight.^4)+1./2.*pi.*d.*rho.*(r_b.^2)+(L_weight.^2).*m_weight+gamma.*(1./4.*rho.*A.*(L_throw.^4)+1./2.*pi.*d.*rho.*(r_s.^2)+(L_throw.^2).*m_object))); Ipsum = integral( Lorum , phi_b, phi_e);
Which gives the following error:
Error using .* Matrix dimensions must agree.Error inGroup_23_all_formulas_variablesneedtobeputin>@(Theta)(-painfully long formula-)Error in integralCalc/iterateScalarValued (line 314) fx = FUN(t);Error in integralCalc/vadapt (line 132) [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);Error in integralCalc (line 75) [q,errbnd] = vadapt(@AtoBInvTransform,interval);Error in integral (line 88)Q = integralCalc(fun,a,b,opstruct);Error in Group_23_all_formulas_variablesneedtobeputin (line 69) Ipsum = integral( Lorum , phi_b, phi_e);
I'd appreciate any help I can get, as I'm feeling pretty lost at the moment. Thank you again for your time!
Best Answer