MATLAB Answers

Error - Undefined function or variable

2 ビュー (過去 30 日間)
Shimon Katzman
Shimon Katzman 2019 年 11 月 25 日
Commented: Star Strider 2019 年 11 月 26 日
Hello everybody.
I am trying to make an if loop but the problem is that "epsc" is undefined veriable.
Is there a better way to make it?
Thank you very much.
b=300; %mm
d=400; %mm
fc=40; %Mpa
Ecshah=57000/145*(fc*145)^0.5; %Mpa
Es=200000; %Mpa
As=2400; %mm^2
fy=400; %Mpa
eps0=1.027*10^-7*fc*145+0.00195;
epscu=3.5/1000;
kshah=0.025*fc*10^3;
A=Ecshah*eps0/fc;
epscmv = linspace(0.05, 3.5, 500)*1E-3;
for i=1:numel(epscmv);
epscm = epscmv(i);
if epsc<=eps0
funCshah=@(epsc) fc*(1-(1-epsc./eps0).^A);
elseif epsc>eps0
funCshah=@(epsc) fc*exp(-kshah*(epsc-eps0).^1.15);
end
end
compression=@(c) b*fc*c/epscm*integral(funCshah,0,epscm)/1000;
tension=@(c) min(Es*(d-c)/c*epscm*As/1000,fy*As/1000);
c(i)=fsolve(@(c) compression(c)-tension(c),1);
Getting the error:
Undefined function or variable 'epsc'.
Error in Untitled (line 16)
if epsc<=eps0

  4 件のコメント

表示 1 件の古いコメント
Shimon Katzman
Shimon Katzman 2019 年 11 月 25 日
Mr Jim. Unfortunetly you did not understan the code. Epsc is a varaible that uses as a limit of the integral...
Jim Riggs
Jim Riggs 2019 年 11 月 25 日
Please explain. What is the value of epsc?
In the context:
funCshah=@(epsc) fc*(1-(1-epsc./eps0).^A)
and also
funCshah=@(epsc) fc*exp(-kshah*(epsc-epsc0).^1.15)
epsc is a place-holder and represents the argument of function funCshah. When function funCshah is called, a numerical value must be supplied as the argument to the function. Therefore, when function funCshah is called, internally epsc has the value of the argument to the function.
In the context
if epsc<=eps0
This is a comparison of two values, so epsc and eps0 must both be defined as variables, and their values are compared. The error message that you are getting is that, in this context, the variable epsc has no definition. It must be defined.
Shimon Katzman
Shimon Katzman 2019 年 11 月 26 日
I know that something wrong with my code, therefore i ask for a new suggestion. Epsc gets a value only in the line of the "compression=..." Which means it gets the values of the integral

サインイン to comment.

採用された回答

Star Strider
Star Strider 2019 年 11 月 26 日
My apologies for not seeing this Question earlier.
I am not certain what you want to do.
Taking a guess, this runs without error:
b=300; %mm
d=400; %mm
fc=40; %Mpa
Ecshah=57000/145*(fc*145)^0.5; %Mpa
Es=200000; %Mpa
As=2400; %mm^2
fy=400; %Mpa
eps0=1.027*10^-7*fc*145+0.00195;
epscu=3.5/1000;
kshah=0.025*fc*10^3;
A=Ecshah*eps0/fc;
epscmv = linspace(0.05, 3.5, 500)*1E-3;
c = zeros(size(epscmv)); % Preallocate
for i=1:numel(epscmv)
epscm = epscmv(i);
funCshah=@(epsc) fc*(1-(1-epsc./eps0).^A) .* (epsc<=eps0) + fc*exp(-kshah*(epsc-eps0).^1.15) .* (epsc>eps0);
compression=@(c) b*fc*c/epscm*integral(funCshah,0,epscm)/1000;
tension=@(c) min(Es*(d-c)/c*epscm*As/1000,fy*As/1000);
c(i)=fsolve(@(c) compression(c)-tension(c),1);
end
figure
plot(epscmv, c)
grid
xlabel('\epsilon (cm)')
ylabel('c(\epsilon)')
The ‘funCshah’ function eliminates the if block (and the necessity of having to define ‘epsc’ first) by using ‘logical indexing’, so that the first part of the function:
fc*(1-(1-epsc./eps0).^A)
returns the appropriate values when ‘(epsc<=eps0)’ is true, and the second part of the function:
fc*exp(-kshah*(epsc-eps0).^1.15)
returns the appropriate values when ‘(epsc>eps0)’ is true. Since ‘epsc’ is appropriately passed as an argument, the test is done inside the function and the if block is not necessary.
If my guess is not correct, make appropriate changes to get the result you want.

  2 件のコメント

Shimon Katzman
Shimon Katzman 2019 年 11 月 26 日
Star, once again, cant find the words to describe how much i appreciate and thankfull to you.
Star Strider
Star Strider 2019 年 11 月 26 日
As always, my pleasure!
Your Questions provide interesting challenges!

サインイン to comment.

More Answers (2)

Jim Riggs
Jim Riggs 2019 年 11 月 25 日
編集済み: Jim Riggs 2019 年 11 月 25 日
Line 16:
if epsc<=eps0
Variable epsc is not defined.

  0 件のコメント

サインイン to comment.


Shimon Katzman
Shimon Katzman 2019 年 11 月 25 日
Please HELP.
Thank You..

  1 件のコメント

Jim Riggs
Jim Riggs 2019 年 11 月 25 日
Don't add comments as an answer.

サインイン to comment.

サインイン してこの質問に回答します。


Translated by