This statement is not inside any function. (It follows the END that terminates the definition of the function "trap_wfp610".)

%% function [ w ] = trap_wfp610( n ) % Calculates the work done using numerical integration and the trapezoidal rule % Detailed explanation goes here h=(5*10^-2)/n; a=0; b=5*10^-2; f=@(a)(5*(10^5)*a+10^5)*pi*(5*10^-2)^2; g=@(b)(5*(10^5)*b+10^5)*pi*(5*10^-2)^2; w=h/2*(f(a)+g(b)); end
%% syms x k1=500000 k2=10^5 p=(k1*x+k2)*pi*.05^2 W=int(p,x,0,5*10^-2)
%% error=abs((w-W)/W)*100

 採用された回答

Kevin, it's hard to tell what exactly you would like to do and what is going wrong. One thing you could do is do both computations within the same function and return all results:
function [ w,Ws,error ] = trap_wfp610( n )
% Calculates the work done using numerical integration and the trapezoidal rule
% Detailed explanation goes here
h = (5*10^-2)/n;
a = 0;
b = 5*10^-2;
f = @(a)(5*(10^5)*a+10^5)*pi*(5*10^-2)^2;
g = @(b)(5*(10^5)*b+10^5)*pi*(5*10^-2)^2;
w = h/2*(f(a)+g(b));
syms x
k1 = 500000
k2 = 10^5
p = (k1*x+k2)*pi*.05^2
Ws = int(p,x,0,5*10^-2)
error = abs((w-Ws)/Ws)*100;
end

3 件のコメント

kevin
kevin 2014 年 12 月 11 日
When I run this code under one function it says that there aren't enough input arguments.
Have you assigned a value to n? In other words try
[ w,Ws,error ] = trap_wfp610( 3 )
or
n = 3;
[ w,Ws,error ] = trap_wfp610( n )
in the MATLAB command window.
kevin
kevin 2014 年 12 月 11 日
That does it Thank you

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2014 年 12 月 11 日

コメント済み:

2014 年 12 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by