Why Value of type "tf"is not convertible to double?

조회 수: 23 (최근 30일)
pawel Wisniewski
pawel Wisniewski 2022년 1월 22일
댓글: Cris LaPierre 2022년 1월 23일
clc;
clear all;
x0=[0 0 0 0 0 0 ];
tic
xOptSim=fminsearch(@robot,x0);
car_sys = 500 s + 12500 ----------------------- 200 s^2 + 500 s + 12500 Continuous-time transfer function.
Warning: Ignoring extra legend entries.
Unable to perform assignment because value of type 'tf' is not convertible to 'double'.

Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});

Caused by:
Error using double
Conversion to double from tf is not possible.
t2=toc;
function [car_sys,u1] = robot(parametry)
X1=parametry(1);
X2=parametry(2);
X3=parametry(3);
X4=parametry(4);
X5=parametry(5);
X6=parametry(6);
m = 200; %kg
b = 500; %Ns/m
k = 12500; %N/m
car_sys = tf([b k],[m b k])
t = 0:0.001:10;
wd=7;
% Respuesta a bajas frecuencias
figure
u1 = sin(wd/2*t)+cos(wd*t);
lsim(car_sys, u1, t)
title('Niska charakterystyka częstotliwościowa')
legend('Odpowiedź systemu' , 'Lokalizacja' , 'SE')
ylim([-4 4])
end

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 1월 23일
I believe the issue is because the order of your function outputs is not correct. The first output of your function needs to be the solution, u1. Try reversing the order of your output arguments.
x0=[0 0 0 0 0 0 ];
xOptSim=fminsearch(@robot,x0);
car_sys = 500 s + 12500 ----------------------- 200 s^2 + 500 s + 12500 Continuous-time transfer function.
Warning: Ignoring extra legend entries.
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-10001.

Error in fminsearch (line 201)
fv(:,1) = funfcn(x,varargin{:});
function [u1,car_sys] = robot(parametry)
X1=parametry(1);
X2=parametry(2);
X3=parametry(3);
X4=parametry(4);
X5=parametry(5);
X6=parametry(6);
m = 200; %kg
b = 500; %Ns/m
k = 12500; %N/m
car_sys = tf([b k],[m b k])
t = 0:0.001:10;
wd=7;
% Respuesta a bajas frecuencias
figure
u1 = sin(wd/2*t)+cos(wd*t);
lsim(car_sys, u1, t)
title('Niska charakterystyka częstotliwościowa')
legend('Odpowiedź systemu' , 'Lokalizacja' , 'SE')
ylim([-4 4])
end
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2022년 1월 23일
The new error is because your solution vector, u1, is not the same size as x0. One thing to look into is why you are not using your X values in your function.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by