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
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 个评论

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?
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.
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 Exchange 中查找有关 C Shared Library Integration 的更多信息

产品

版本

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by