how to solve error mentioned in following program?

1 次查看(过去 30 天)
This is my program
[t,Vc]=ode45('capvolt',[0 20e-3],[0])
%capvolt is the function file name
subplot(1,2,1)
plot(t,Vc,'r')
grid
title('Vc')
xlabel('time in sec')
ylabel('voltage Vc')
Vc_analy=10*(1-exp(-10*t))
subplot(1,2,2)
plot(t,Vc_analy)
grid
xlabel('time in sec')
ylabel('voltage Vc_analy')
title('Vc_analy')
%program of the function file capvolt
dVc=100-10*Vc
function dVc=capvolt(t,Vc)
And the error i am facing is : Function definitions are not permitted at the prompt or in scripts.

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-11-2
编辑:Azzi Abdelmalek 2013-11-2
Your function is not correct. It should be
function dVc=capvolt(t,Vc)
dVc=100-10*Vc
Save this function as capvolt.m, then you can call your function
[t,Vc]=ode45('capvolt',[0 20e-3],[0])

Community Treasure Hunt

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

Start Hunting!

Translated by