Hello Everybody
I am trying to solve a state space equation using ODE45 so that I can plot my states. My equation is of the form idot=Ai +Bv, the dimensions are [4,1]=[4;4]*[4,1]+[4,4][4,1]
When I run the code, I get " errors in 'sys' " but I dont know how to fix them. I have attached a picture of my code. Please kindly assist, thank you in advance.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 12일

0 개 추천

You are trying to run sys() without passing in values for t or i . sys() then fails when it needs to use one of the input variables.
You might possibly be pressing the green Run button. When you use the Run button, unless you take special steps, MATLAB will run the function without passing anything in to it.
When you run a function that has input arguments, MATLAB never pokes around looking in calling environments to see whether it can find a variable with a matching name. You must pass values to the function explicitly if you want the function to process the inputs.

댓글 수: 5

Basetsana Sebolao
Basetsana Sebolao 2021년 5월 12일
Thank you, I realise my mistake. I tried passing in the arguments for t and i in the command window however I get an error saying that " sys must return a column vector". I have attached an image of the code
Your current code tries to calculate a 4 x 4 matrix, which implies that you expect your boundary inputs, i to be 4 x 4. But your boundary is going to be received as a column vector. So early on in the function you should
i = reshape(i, 4, 4);
and then at the end of the function,
di = di(:);
Basetsana Sebolao
Basetsana Sebolao 2021년 5월 12일
This is my first time trying to solve a state space equation on Matlab, I am a bit lost, please bear with me. I was expecting to get a 4 x 1 matrix, my input matrix, v is also a 4 x 1 matrix however in your response you said that my i matrix is actually a 4 x 4 matrix, may i ask why that is so?
Walter Roberson
Walter Roberson 2021년 5월 12일
Your A is 4 x 4 and you use .* which is element-by-element multiplication, so you get a 4 x 4 output.
If i is 4 x 1 then you should use A*i to get a 4 x 1 result, and likewise the other multiplication in the expression would have to be * instead of .*
Basetsana Sebolao
Basetsana Sebolao 2021년 5월 12일
ohh I see, thank you very much!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by