I've found this code that may help me a lot.
I cannot run, it keeps saying:
Error using type
Too many output arguments.
my version is 2014b
the code is
function [t,y]=valori(type)
a=340;
S=0.25;
x10=0.85;
U=144;
if (type == 1)
Ac=0.0034;
Vp=0.32;
Lc=0.3;
H=3.2613e4;
W=0.3689;
else
if (type == 2)
Ac=0.0033;
Vp=0.025;
Lc=1.22;
H=0.09e5;
W=0.1;
else
Ac=0.0090;
Vp=0.001;
Lc=2.8;
H=1.55e4;
W=0.1587;
end
end
[t,y]=greitzer2(a,Ac,Vp,Lc,U,H,W,x10,S);
end
function [t,y]=greitzer2(a,Ac,Vp,Lc,U,H,W,x10,S)
wh=a*sqrt(Ac/(Vp*Lc));
B=U/(2*wh*Lc);
k=x10-S*(x10-(1/3)*(x10.^3));
[t,y]=ode45(@(t,y)greitzer10(H,W,B,U,Ac,y,S,k),[0 100],[0,0]);
subplot(2,2,1)
plot(t,y(:,1))
xlabel('t')
ylabel('\phi_c')
subplot(2,2,2)
plot(y(:,1),y(:,2))
xlabel('\phi_c')
ylabel('\psi')
subplot(2,2,3)
plot(t,y(:,2))
xlabel('t')
ylabel('\psi')
end
function dydt = greitzer10(H,W,B,U,Ac,y,S,k)
dydt = [ ((3*H*Ac*B)/(W*U))*((y(1)-(1/3)*((y(1).^3)))-y(2)); ((W*U)/(3*H*Ac*B))*(y(1)-(S*y(2)+k)) ];
end
this might be a missing part:
function y=carcomp(C0,H,x,W)
y=C0+H*(1+(3/2)*((x/W)-1)-(1/2)*(((x/W)-1).^3));

 採用された回答

per isakson
per isakson 2019 年 12 月 17 日
編集済み: per isakson 2019 年 12 月 17 日

1 投票

I fail to reproduce the error you report
>> [t,y] = valori( 2 );
>> [t,y] = valori( 1 );
>> [t,y] = valori( 3 );
no error, no warning and produces a figure with three diagrams.
However
>> [t,y] = valori( type );
Error using type
Too many output arguments.
>>
"type" is the name of a function that doesn't return any output. Try
>> type=1; [t,y] = valori( type );
That works, but now you'll get unexpexted results if you try to use the function, type
Conclusion: Avoid to use function names as names of variables.

4 件のコメント

Paul Rogers
Paul Rogers 2019 年 12 月 17 日
man, you made my day! Can't immagine how important this was to me.
One last thing, ho can I plot:
function y=carcomp(C0,H,x,W)
y=C0+H*(1+(3/2)*((x/W)-1)-(1/2)*(((x/W)-1).^3));
end
in the last missing quadrant?
per isakson
per isakson 2019 年 12 月 17 日
編集済み: per isakson 2019 年 12 月 17 日
Add
%
C0 = 0; % or a better value
cc = carcomp( C0, H, t, W );
subplot(2,2,4)
plot( t, cc )
xlabel('t')
ylabel('carcomp')
at the end of the function, valori. That fills the "missing quadrant", but maybe not with the data you expected.
Paul Rogers
Paul Rogers 2019 年 12 月 17 日
function [t,y]=valori(type)
a=340;
S=0.25;
x10=0.85;
U=144;
if (type == 1)
Ac=0.0034;
Vp=0.32;
Lc=0.3;
H=3.2613e4;
W=0.3689;
else
if (type == 2)
Ac=0.0033;
Vp=0.025;
Lc=1.22;
H=0.09e5;
W=0.1;
else
Ac=0.0090;
Vp=0.001;
Lc=2.8;
H=1.55e4;
W=0.1587;
end
end
[t,y]=greitzer2(a,Ac,Vp,Lc,U,H,W,x10,S);
end
function [t,y]=greitzer2(a,Ac,Vp,Lc,U,H,W,x10,S)
wh=a*sqrt(Ac/(Vp*Lc));
B=U/(2*wh*Lc);
k=x10-S*(x10-(1/3)*(x10.^3));
[t,y]=ode45(@(t,y)greitzer10(H,W,B,U,Ac,y,S,k),[0 100],[0,0]);
subplot(2,2,1)
plot(t,y(:,1))
xlabel('t')
ylabel('\phi_c')
subplot(2,2,2)
plot(y(:,1),y(:,2))
xlabel('\phi_c')
ylabel('\psi')
subplot(2,2,3)
plot(t,y(:,2))
xlabel('t')
ylabel('\psi')
end
function dydt = greitzer10(H,W,B,U,Ac,y,S,k)
dydt = [ ((3*H*Ac*B)/(W*U))*((y(1)-(1/3)*((y(1).^3)))-y(2)); ((W*U)/(3*H*Ac*B))*(y(1)-(S*y(2)+k)) ];
end
function y=carcomp(C0,H,x,W)
y=C0+H*(1+(3/2)*((x/W)-1)-(1/2)*(((x/W)-1).^3));
end
C0 = 0; % or a better value
cc = carcomp( C0, H, t, W );
subplot(2,2,4)
plot( t, cc )
xlabel('t')
ylabel('carcomp')
then i type in the command
type=1; [t,y] = valori( type );
but it says this:
Error: File: valori.m Line: 63 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "carcomp".)
per isakson
per isakson 2019 年 12 月 18 日
編集済み: per isakson 2019 年 12 月 18 日
"This statement is not inside any function." Why did you put it at the end of the file?
Read up on function and Local Functions
Here is a screen clip of the end of your file valori.m
Comments
  • Upper left corner. With an indention of 4, I find it easier to see the scope of the functions.
  • Upper right corner. The red box shows that the Code Analyzer has spotted a syntax error. Try to understand and fix that problem before running the code. See Check Code with the Code Analyzer
  • The arrow points at the the end of the function valori.
Move the lines 61-66 to the end of the function valori.

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2014b

質問済み:

2019 年 12 月 16 日

編集済み:

2019 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by