Trying to use function ,didnt work?

function [Delta]= finddeflexion(Length)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
Length = input(prompt);
Delta = W*(Length^3)/(8*E*I);
when i typed it like this it gave me error sayin to type the function part like so and i dont understand why
function [Delta]= finddeflexion(~)
the code then works fine

2 件のコメント

Mann Baidi
Mann Baidi 2023 年 12 月 12 日
Why are you having "Length" as function parameter?
Bastian
Bastian 2023 年 12 月 12 日
not sure what you mean by function parameter

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2023 年 12 月 12 日

0 投票

when i typed it like this it gave me error
I doubt it gave you an error. It certainly doesn't give me one.
You probably got a Code Analyzer warning saying that the input argument "Length" is not being used. If you want it to be used remove the line which overwrites it:
function [Delta]= finddeflexion(Length)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
%Length = input(prompt);
Delta = W*(Length^3)/(8*E*I);
end

10 件のコメント

Bastian
Bastian 2023 年 12 月 12 日
still dosent work wont let me input length which i am trying to do for quite some time
finddeflexion(length)
Error using length
Not enough input arguments.
Bastian
Bastian 2023 年 12 月 12 日
if instead of e I and w i use the actual values in the equation it worked once but then same error
Matt J
Matt J 2023 年 12 月 12 日
You have a lower case 'L' in length.
Matt J
Matt J 2023 年 12 月 12 日
finddeflexion(10) %it works
ans = 2.5298
function [Delta]= finddeflexion(Length)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
%Length = input(prompt);
Delta = W*(Length^3)/(8*E*I);
end
Bastian
Bastian 2023 年 12 月 12 日
finddeflexion(Length)
Unrecognized function or variable 'Length'.
Did you mean:
>> finddeflexion(length)
Error using length
Not enough input arguments.
Matt J
Matt J 2023 年 12 月 12 日
編集済み: Matt J 2023 年 12 月 12 日
Either version is fine, but you should not be passing variables that haven't been assigned values to the function.
Length=10;
Delta = finddeflexion(Length) %it works
Delta = 2.5298
length=5;
Delta = finddeflexion(length) %it works - but Matlab's builtin length command is now unavailable
Delta = 0.3162
function [Delta]= finddeflexion(Length)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
%Length = input(prompt);
Delta = W*(Length^3)/(8*E*I);
end
Bastian
Bastian 2023 年 12 月 12 日
iam trying to run it as a script and that is when it doesn't seem to be working for me. i thought if i hit run it wourld display [Delta]= finddeflexion(Length) but when i check options it says i can change what is in (length) to the value i want to put in but it wont let it run (length)
Matt J
Matt J 2023 年 12 月 12 日
編集済み: Matt J 2023 年 12 月 12 日
In my last post, I ran it for you as a script. That is why you can see the output. If you put what I coded above in a script and hit Run, with no additional options, it will work.
Bastian
Bastian 2023 年 12 月 12 日
if you look at these images you will understand what i am trying to say
i want it s when i run it it displays as so
[Delta]= finddeflexion(Length)
and then let me the user type in the value for length
in first screen shot i have underlined what i mean by options when running, it seems that i have to put in value first like so, instead of just pressing run and changing the value of length in command window
Matt J
Matt J 2023 年 12 月 12 日
編集済み: Matt J 2023 年 12 月 12 日
instead of just pressing run and changing the value of length in command window
Yes, we removed the line where you are prompted for the Length from the command window.
If you want to set the Length variable in the command window, then you should put that line back in, but remove "Length" from the function signautre line
function [Delta]= finddeflexion() %or finddeflexion(~)
E= 4.2*(10.^10);
I = 1*(10.^-5);
W = 8500;
prompt = "What is the length of the blade? ";
Length = input(prompt); %<--- put this line back in
Delta = W*(Length^3)/(8*E*I);
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2023 年 12 月 12 日

編集済み:

2023 年 12 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by