Why is MATLAB producing the wrong output with this function?
Afficher commentaires plus anciens

So using these piecewise functions, I am trying to find v(x) which is beamDef in my function, given a user inputted value of x which is beamLoc.
function [beamDef] = FindDeflection(beamLoc)
A = (1/3.19e9);
x1 = (beamLoc>0)&(beamLoc<=120);
x2 = ((beamLoc>120)&(beamLoc<=240));
x3 = ((beamLoc>240)&(beamLoc<=360));
beamDef = A*((800*(x1.^3))-(13.68.*(10^6).*x1)-(2.5*(x1.^4)));
beamDef = A*((800*(x2.^3))-(13.68.*(10^6).*x2)-(2.5*((x2.^4))+(2.5.*(x2-120).^4)));
beamDef = A*((800*(x3.^3))-(13.68.*(10^6).*x3)-(2.5*((x3.^4))+(2.5.*(x3-120).^4))+(600.*((x3-240).^3)));
end
While trying to test when beamLoc = 115 on my main script, it gives me a beamDef = -2.763 when it should actually be -0.249. I've tried rewriting the equations given in many different ways but I still can't get MATLAB to produce the correct output.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!