Error using plot data must be numeric datetime duration or an array convertible to double

Hi everyone. I wrote the following code but I get this error: "error using plot: Data must be numeric, datetime, duration or an array convertible to double." Kindly resolve this issue. clear al...

Error using «plot» : Data must be numeric, datetime, duration or an array convertible to double??

Muhammad Sanwal

Hi everyone. I wrote the following code but I get this error:

«error using plot: Data must be numeric, datetime, duration or an array convertible to double.»

Kindly resolve this issue.

clear all

close all

clc

s=tf(‘s’);

H = 1/(12*s+1);

Gp = 70/(50*s+1);

Gv=0.02/(4*s+1);

Gc = 0.0799;

Tsp = 1/s;

D = -0.01/s;

% Open loop transfer function:

GsHs = Gp*Gv*H;

sys = feedback(Gc*Gp*Gv,H);

stepinfo(sys)

t = 0:0.1:15;

[y,t] = step(sys);

e = 1-y; %this is E(s) due to Tsp(s) and D(s)

figure(1)

plot(t,e,‘linewidth’,2)

xlim([0,t(end)])

grid

title(‘error’)

figure(2)

[y,t] = step(sys);

U = e.*Gc;

subplot(4,1,1);

plot(t,U,‘linewidth’,2);

grid

title(‘U(s)’)

[y,t] = step(sys);

U0 = U.*Gv;

subplot(4,1,2);

step(U0);

grid

title(‘U0(s)’)

[y,t] = step(sys);

T = (U0+D).*Gp;

subplot(4,1,3);

plot(t,T,‘linewidth’,2);

grid

title(‘T(s)’)

[y,t] = step(sys);

Tm = T.*H;

subplot(4,1,4);

plot(t,Tm,‘linewidth’,2);

grid

title(‘Tm(s)’)

Accepted Answer

Star Strider

Apparently, the error is that subplot attempts to plot a transfer function step response without evaluating it.

Try this instead:

[y,t] = step(sys);

T = (U0+D).*Gp;

[y1,t1] = step(T);

subplot(4,1,3);

plot(t1,y1,‘linewidth’,2);

grid

title(‘T(s)’)

[y,t] = step(sys);

[y2,t2] = step(T.*H);

subplot(4,1,4);

plot(t2,y2,‘linewidth’,2);

grid

title(‘Tm(s)’)

That ran without error.

You need to determine if it does what you want.


More Answers (0)

See Also

Categories

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Error using plot Data must be numeric, datetime, duration or an array convertible to double.

Mary Enloe

  • Direct link to this question

 ⋮ 

  • Direct link to this question

>> clear all

>> close all

>> syms s

>> F = (2*s+1)/(s^3 +3*s^2+4*s+2)

F =

(2*s + 1)/(s^3 + 3*s^2 + 4*s + 2)

>> t = [0:0.1:200];

>> f = ilaplace(F)

f =

exp(-t)*(cos(t) + 2*sin(t)) — exp(-t)

>> plot(t,f)

Error using plot

Data must be numeric, datetime, duration or an array

convertible to double.

I’m getting an error for my code and my teacher isn’t sure what the issue is. I am able to plot smaller parts of this function but not the whole this. From what I understand from other posts it seems like the issue may be a symbolic variable or how this is defined? Any answers?

Accepted Answer

Abolfazl Chaman Motlagh

  • Direct link to this answer

 ⋮ 

  • Direct link to this answer

f is a symbolic expression not a function or vector. you can create a function with this expression, then plot the value of function on your desired points:

F = (2*s+1)/(s^3 +3*s^2+4*s+2);

f = ilaplace(F); %symbolic expression

f = symfun(f,t); %symbolic function with f as it’s expression and t as it’s input

plot(t,f(t)) % you need to put all t in argument of f cause now it is a function


More Answers (1)

Walter Roberson

  • Direct link to this answer

 ⋮ 

  • Direct link to this answer

F = (2*s+1)/(s^3 +3*s^2+4*s+2)

F = 

f = ilaplace(F, s, T)

f = 

y = double(subs(f, T, t));

title(‘0:0.1:200’)

fplot(f, [0 100], ‘meshdensity’, 27)

title(‘fplot[0,10]’)

The default meshdensity is 23. If you do not use the option with at least 27 you will get the wrong plot. 26 will get a plot that almost looks right unless you change the ylim.

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

MathWorks - Domain Selector

error using plot data must be numeric, datetime, duration or an array convertible to double

Direct link to this question

Direct link to this question

0 Comments

Accepted Answer

Direct link to this answer

Direct link to this answer

0 Comments

More Answers (0)

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

error using plot data must be numeric, datetime, duration or an array convertible to double

Direct link to this question

Direct link to this question

0 Comments

Accepted Answer

Direct link to this answer

Direct link to this answer

0 Comments

More Answers (0)

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

Plotting error ‘Data must be numeric, datetime, duration or an array convertible to double.’

Direct link to this question

Direct link to this question

0 Comments

Accepted Answer

Direct link to this answer

Direct link to this answer

0 Comments

More Answers (0)

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

error using plot data must be numeric, datetime, duration or an array convertible to double

Direct link to this question

Direct link to this question

0 Comments

Accepted Answer

Direct link to this answer

Direct link to this answer

0 Comments

More Answers (0)

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

Error using plot Data must be numeric, datetime, duration or an array convertible to double. Error in prueba3 (line 12) plot(x,Vol);

Direct link to this question

Direct link to this question

0 Comments

Accepted Answer

Direct link to this answer

Direct link to this answer

0 Comments

More Answers (0)

See Also

Categories

Community Treasure Hunt

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

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文 Chinese
    • English
  • 日本 Japanese (日本語)
  • 한국 Korean (한국어)

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Источник

$begingroup$

I’m currently working on an assignment where we want to plot an output function.

Since our input signal( v(t) )is in the Time domain and our transfer function ( H(s) ) is in the S domain.
we want to bring our input signal to the S domain so we can simply use multiplication and then bring it back to the time domain to plot.

The error I’m getting is:
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.

syms s C R L T n

C = (36)*10^(-6); % Our given values for capacitance, inductance and resistance
L = 0.18;
R = 100;
T = 1/50; % Period
H = 1/(C*R*s + C*L*s^2 + 1);        %Transfer function
y = 3/2;                           %c_0

for n = -5:1:5
    c_k = (((-1)^n)/(pi*(2*n+1)))*exp(1i*(2*n+1)*100*pi*t);
    y = y + c_k;
end
V = laplace(y);
Vc = V * H;
vc = ilaplace(Vc);

vpa(vc);
plot(t,vc);```

asked Jan 12, 2021 at 16:56

mastaresplinter's user avatar

$endgroup$

$begingroup$

I see different issues in this RLC filter circuit.

Here are the modifications you should operate at the end of your program:

vc = real(ilaplace(Vc));%"real" is compulsory even if... it is already real (very small imaginary parts way cree on) 
vvc = string(vc);
close all;hold on;axis([-1,1,-3,3]);
f=str2func(['@(t)(',vvc,')']);%in order to get a function
for t=-1:0.1:1
    plot(t,f(t),'.')
end; 
  1. You have to change types : «syms» type has to be converted into «string» type

  2. You have to convert to real.

  3. «t» is symbolic: Matlab cannot use it as it is; you know that you must give to $t$ a range of values, for example $t=-1:0.1:1$.

  4. We use here the so-called «immediate definition» of a function (https://uk.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html)

  5. What is this function $y$ ? It looks like a truncated Fourier series expansion of a ramp function ?

  6. vpa(…) isn’t useful. Instead of for example $2/3$, it gives you $0.66666666666666666666666666…$ with thirty decimals… It’s better to keep the fractional form.

  7. The value of T isn’t used.

answered Jan 12, 2021 at 17:36

Jean Marie's user avatar

Jean MarieJean Marie

71.3k7 gold badges43 silver badges103 bronze badges

$endgroup$

1

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

Bolod

0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

1

Как решить дифференциальное уравнение и получить графики?

05.04.2021, 14:41. Показов 1145. Ответов 24

Метки matlab, дифференциальное уравнение, задача (Все метки)


Добрый день!
Прошу консультации по вопросу решения дифференциального уравнения в Matlab. Необходимо решить следующее уравнение:
y»+3y+y=5g+3g’, при этом даны начальные условия y(0)=1, y'(0)=-1 и входное воздействие g(t)=1(t).
Я записываю уравнение в программе следующим образом:

Matlab M
1
y=dsolve('D2y+3*y+y=5*g+3*Dg','y(0)=1','Dy(0)=-1')

а вот как правильно записать g(t)=1(t) я не знаю, перебрал разные варианты, но ничего не получается.
Помогите пожалуйста.

А таким образом я могу получить графики? Только получается надо добавлять во входное воздействие не только step, но и дельта функцию, и это получается без нач усл. Для нач условии брать звено transfer fcn with initial condition.

Миниатюры

Как решить дифференциальное уравнение и получить графики?
 

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



59 / 17 / 4

Регистрация: 19.11.2014

Сообщений: 141

05.04.2021, 18:50

2

1(t) — это, если не путаю, функция Хевисайда, т.е. =0 при t<0 и =1 при t>0. Если так, то (при t начиная от 0+) g=1 и g’=0.
Т.е., ДУ просто y»+3y+y=5.



1



Bolod

0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 21:01

 [ТС]

3

Решаю по аналогии еще два уравнения:
1) y’=2g+g’

Matlab M
1
2
3
4
y=dsolve('Dy=2','Dy(0)=-1')
t=0:0.01:10;
a1=y;
plot(t,a1,'k')

2) 5y»’+3y»+4y=2g+2g»

Matlab M
1
2
3
4
y=dsolve('5*D3y+3*D2y+4*y=2','y(0)=1','Dy(0)=-1')
t=0:0.01:10;
a1=y;
plot(t,a1,'k')

Входное воздействие и начальные условия те же.
В первом случае вместо ответа выдает [ empty sym ]. Во втором ответом является очень длинное выражение, также не строится график, пишет ошибку «Data must be numeric, datetime, duration or an array convertible to double.»

Добавлено через 11 минут
Также пробовал такой вариант

Matlab M
1
2
3
4
y=dsolve('5*D3y+3*D2y+4*y=2*heaviside(t)+2*D2heaviside(t)','y(0)=1','Dy(0)=-1')
t=0:0.01:10;
a1=y;
plot(t,a1,'k')

Результат аналогичный, ничего не считает.



0



572 / 361 / 186

Регистрация: 11.01.2019

Сообщений: 1,220

05.04.2021, 21:21

4

Bolod, g — функция Хевисайда, ее производная g’ — дельта-функция, равна бесконечность для t=0. Вы свою задачу правильно сформулировали ?



0



0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 21:25

 [ТС]

5

Да, правильно. Задание выглядит именно так, как написано.



0



Diusha

59 / 17 / 4

Регистрация: 19.11.2014

Сообщений: 141

05.04.2021, 21:36

6

В 1-м случае написано противоречивое условие: ‘Dy=2′,’Dy(0)=-1’
— производная всегда равна 2 и производная в нуле равна -1.

Во втором:
Data must be numeric — данные д.б. числовыими.
dsolve выдает ответ символьный — функция от t. Туда надо подставить числа:

Matlab M
1
a1=eval(subs(y,t));

Кроме того, второе ур. третьей степени => д.б. задано еще нач. значение для второй производной. Иначе в ответе появятся неопределенная константа.



1



572 / 361 / 186

Регистрация: 11.01.2019

Сообщений: 1,220

05.04.2021, 21:41

7

Цитата
Сообщение от Bolod
Посмотреть сообщение

Да, правильно. Задание выглядит именно так, как написано.

что сказано в задании по методике решения ? численным, символьным, операторным способом ?



0



Bolod

0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 21:49

 [ТС]

8

Добрый день. В задании сказано решать через функцию dsolve.

Добавлено через 2 минуты
Так тоже не получается:

Matlab M
1
2
3
4
y=dsolve('Dy=2*heaviside(t)+Dheaviside(t)','Dy(0)=-1')
t=0:0.01:10;
a1=y;
plot(t,a1,'k')

Добавлено через 2 минуты
Ничего не сказано, но даны примеры и в них решается через dsolve. Правда в этих примерах правая сторона уравнения равна 0, а не входному воздействию.



0



59 / 17 / 4

Регистрация: 19.11.2014

Сообщений: 141

05.04.2021, 21:57

9

Цитата
Сообщение от Bolod
Посмотреть сообщение

‘Dy(0)=-1’

Предполагаю, что д.б. не Dy, а y(0)=-1



0



0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 22:02

 [ТС]

10

в задании написано y'(0)=-1 и y(0)=1.

Миниатюры

Как решить дифференциальное уравнение и получить графики?
 



0



59 / 17 / 4

Регистрация: 19.11.2014

Сообщений: 141

05.04.2021, 22:09

11

Для ДУ n-ой степени должны быть заданы начальные условия для производных порядка от 0 до n-1 (производная порядка 0 — просто сама функция).
Д.б. заданы:
а) y(0), y'(0)
б) y(0)
в) y(0), y'(0), y»(0)
Жалуйтесь преподу на кривое задание.



0



Bolod

0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 22:13

 [ТС]

12

Завтра задам такой вопрос, но второе уравнение всё-равно не решается, хотя для него начальных условий достаточно.

Matlab M
1
a1=eval(subs(y,t));

Даже это не помогло.
Всё равно большое вам спасибо!



0



tokrab

572 / 361 / 186

Регистрация: 11.01.2019

Сообщений: 1,220

05.04.2021, 22:22

13

Matlab M
1
2
3
4
5
6
syms y(t)
dy=diff(y);
d2y=diff(y,2);
y=dsolve(d2y+3*dy+y==5+3*dirac(t), y(0)==1, dy(0)==-1)
y=simplify(y);
fplot(y,[0 10])



1



Bolod

0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 22:30

 [ТС]

14

Первый у меня решается, таким способом:

Matlab M
1
2
3
4
y=dsolve('D2y+3*y+y=5*heaviside(t)+3*Dheaviside(t)','y(0)=1','Dy(0)=-1')
t=0:0.01:10;
a1=y;
plot(t,a1,'k')

Добавлено через 56 секунд
а вот со вторым и третьим уравнением засада(



0



tokrab

572 / 361 / 186

Регистрация: 11.01.2019

Сообщений: 1,220

05.04.2021, 22:42

15

во втором уравнении начальные условия д.б. только по y

Matlab M
1
2
3
4
5
syms y(t)
dy=diff(y);
y=dsolve(dy==2+dirac(t), y(0)==1)
y=simplify(y);
fplot(y,[0 10])



1



0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 22:46

 [ТС]

16

То есть, для решения третьего уравнения действительно не хватает одного начального условия?



0



572 / 361 / 186

Регистрация: 11.01.2019

Сообщений: 1,220

05.04.2021, 22:53

17

да, как писал выше Diusha, а если не дано, значит принять его равным нулю

Добавлено через 2 минуты
но там еще g», а это уже какой то беспредел)))



0



0 / 0 / 0

Регистрация: 16.12.2018

Сообщений: 35

05.04.2021, 22:58

 [ТС]

18

Спасибо.



0



59 / 17 / 4

Регистрация: 19.11.2014

Сообщений: 141

06.04.2021, 06:54

19

Цитата
Сообщение от tokrab
Посмотреть сообщение

а если не дано, значит принять его равным нулю

Это с какой стати? Почему не -25.3?

Цитата
Сообщение от tokrab
Посмотреть сообщение

но там еще g», а это уже какой то беспредел)))

Не беспредел, а просто 0, если t=0 не трогать.



0



572 / 361 / 186

Регистрация: 11.01.2019

Сообщений: 1,220

06.04.2021, 09:21

20

Цитата
Сообщение от Diusha
Посмотреть сообщение

Сообщение от tokrab
а если не дано, значит принять его равным нулю
Это с какой стати? Почему не -25.3?

это предложение, а не утверждение

Цитата
Сообщение от Diusha
Посмотреть сообщение

Не беспредел, а просто 0, если t=0 не трогать.

поскольку g’ не ноль, а функция Дирака, и реакция линейной системы на функцию Дирака не пустое место, то и g» совсем не ноль, а нечто без предела, также предложенное уравнение характеризуется неустойчивостью, имеет положительные корни, поэтому в совокупности тут полный беспредел))



0



IT_Exp

Эксперт

87844 / 49110 / 22898

Регистрация: 17.06.2006

Сообщений: 92,604

06.04.2021, 09:21

20

Понравилась статья? Поделить с друзьями:
  • Error using mrdivide
  • Error using mpower inputs must be a scalar and a square matrix
  • Error using mesh line 71 data dimensions must agree
  • Error using matrix dimensions must agree matlab
  • Error using loadlibrary matlab