Error using quad (line 70) The integrand function must return an output vector of the same length as the input vector. Error in sprawozdanie1 (line 37) Ssr=quad(x1,-0,6*pi);

3 ビュー (過去 30 日間)
clc;
clear all;
close all;
t=linspace(0,6*pi);
x=2*10*sin(10*pi*t+(pi/10));
y=-0.5*4*cos(4*pi*t+(pi/4))+9;
z=x+3*y;
h=(1/2)*x.*y;
%h=(1/2)*(2*10*sin(10*pi*t+(pi/10)))*(-1/2*4*cos(4*pi*t+(pi/4))+9);
plot(t,x);
hold on
plot(t,y);
hold on
plot(t,z);
hold on
plot(t,h);
hold on
legend ('x(t)', 'y(t)', 'z(t)', 'h(t)')
xlabel('czas t[s]')
%Okres dla x(t)
wx=10*pi;
%T=2pi/w
Tx=2*pi/wx;
%Okres dla y(t)
wy=4*pi;
Ty=2*pi/wy;
%Stworzenie uchwytu do funkcji x(t) w celu obliczenia szukanych wartości
x1=@(t)x;
x2=x.*x;
x3=@(t)x.*x;
Ssr=quad(x1,0,6*pi);
Psr=quad(x3,0,6*pi);
Ws=sqrt(Psr);
Error using quad (line 70)
The integrand function must return
an output vector of the same length
as the input vector.
Error in sprawozdanie1 (line 37)
Ssr=quad(x1,0,6*pi);
Hey, what's the problem with quad option? Thanks for help ;)

回答 (1 件)

Steven Lord
Steven Lord 2021 年 3 月 5 日
x1=@(t)x;
x is a numeric vector. That vector is not necessarily the same size or shape as the array t that quad passes into your function to evaluate the integrand. This function completely ignores the input.
If you want to make x a function of t, then make it a function handle.
x=@(t)2*10*sin(10*pi*t+(pi/10));
Now you'll need to pass t into x whenever you want the numeric value.
x(0:pi/4:pi)
ans = 1×5
6.1803 -2.8814 -11.3473 -17.4669 -19.9750

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by