Error using .^ not enough input arguments

1 回表示 (過去 30 日間)
Alexander
Alexander 2023 年 4 月 11 日
コメント済み: Les Beckham 2023 年 4 月 11 日
I dont know what i am doing wrong here.
I have a function that is meant to take a single input 'a' and output 'L' however i keep getting this error.
Error using .^
Not enough input arguments.
Error in calc_length (line 11)
L = integral( sqrt(1+{power(dy/dx),2}),x1,x2);
Error in Test (line 1)
z = calc_length(2);
Can someone please advise.
Code:
function [L] = calc_length(a)
%UNTITLED6 Summary of this function goes here
% Detailed explanation goes here
x1 = -1;
x2 = 1;
dx = 0.1;
x = 1:10;
(x1<=x)&(x<=x2);
y=(power((2.*x),a)+1).*cos((pi.*x)/2);
dy = diff(y);
L = integral( sqrt(1+{power(dy/dx),2}),x1,x2);
end

採用された回答

Les Beckham
Les Beckham 2023 年 4 月 11 日
編集済み: Les Beckham 2023 年 4 月 11 日
Perhaps you meant this instead
% L = integral( sqrt(1+{power(dy/dx),2}),x1,x2);
% ^ ^ remove the curly braces and move ,2
% inside the parentheses
L = integral(sqrt(1 + power(dy/dx ,2), x1, x2);
Note that this can also be written like this (which explains the mention of .^ in the error message)
L = integral(sqrt(1 + (dy/dx).^2, x1, x2);
  2 件のコメント
Alexander
Alexander 2023 年 4 月 11 日
yeah, that worked. thank you
Les Beckham
Les Beckham 2023 年 4 月 11 日
You are quite welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by