Learning how to use functions

2 ビュー (過去 30 日間)
Tyde Hilderbrandt
Tyde Hilderbrandt 2021 年 11 月 19 日
回答済み: Star Strider 2021 年 11 月 19 日
Hey, I'm trying to learn how to use functions to solve a problem.
A simply supported beam is loaded as shown in the figure below.
Here is what I have in my Main file:
clc,clear
v=[(5/2) 5 3 30exp(6) (16/625) 30];
[V]=deflection_Hilderbrandt(v);
V
and my function file:
function [V]=deflection_Hilderbrandt(x,L,a,E,I,P)
b=L-a
if 0<=x && a>=x
V=((P*b/(6*E*I*L))*(-L^(2)+b^(2))*x+x^(3))
else a<x && L>=x
V=((P*b/(6*E*I*L))*(-L^(2)+b^(2))*x+x^(3)-(L/b)*(x-a)^(3))
end
fprintf('The value of vertical deflection V is %f \n')
end
I am getting an error in the main file as such:
Line 2: invalid floating point constant
Line2: parse error at ']' :usage might be invalid MATLAB syntax
Thank you for the help

採用された回答

Star Strider
Star Strider 2021 年 11 月 19 日
One problem is that there needs to be a multiplication operator between ‘30’ and ‘exp(6)’.
The other problem is that the data need to be separated into thier individual components to be evaluated in ‘deflection_Hilderbrandt’ however where this is done is simply a mater of code design. (I did it in the calling script here.)
If the rest of the code is correect, thiw works and produces the correct result —
v={(5/2) 5 3 30*exp(6) (16/625) 30};
[x,L,a,E,I,P] = v{:}
x = 2.5000
L = 5
a = 3
E = 1.2103e+04
I = 0.0256
P = 30
[V]=deflection_Hilderbrandt(x,L,a,E,I,P);
b = 2
V = 15.2861
The value of vertical deflection V is
V
V = 15.2861
function [V]=deflection_Hilderbrandt(x,L,a,E,I,P)
b=L-a
if 0<=x && a>=x
V=((P*b/(6*E*I*L))*(-L^(2)+b^(2))*x+x^(3))
else a<x && L>=x
V=((P*b/(6*E*I*L))*(-L^(2)+b^(2))*x+x^(3)-(L/b)*(x-a)^(3))
end
fprintf('The value of vertical deflection V is %f \n')
end
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by