if true
A = [x(1)^2 x(1)*y(1) y(1)^2 x(1) 1;
x(2)^2 x(2)*y(2) y(2)^2 x(2) 1;
x(3)^2 x(3)*y(3) y(3)^2 x(3) 1;
x(4)^2 x(4)*y(4) y(4)^2 x(4) 1;
x(5)^2 x(5)*y(5) y(5)^2 x(5) 1;
x(6)^2 x(6)*y(6) y(6)^2 x(6) 1;
x(7)^2 x(7)*y(7) y(7)^2 x(7) 1;
x(8)^2 x(8)*y(8) y(8)^2 x(8) 1;
x(9)^2 x(9)*y(9) y(9)^2 x(9) 1;
x(10)^2 x(10)*y(10) y(10)^2 x(10) 1 ]
end
The integers 1-10 are meant to be subscripts. I've tried using the syms and repmat functions but have not gotten anywhere further.

 채택된 답변

Marta Salas
Marta Salas 2014년 3월 13일

0 개 추천

x = sym('x', [10 1]);
y = sym('y', [10 1]);
if true
A = [x(1)^2 x(1)*y(1) y(1)^2 x(1) 1;
x(2)^2 x(2)*y(2) y(2)^2 x(2) 1;
x(3)^2 x(3)*y(3) y(3)^2 x(3) 1;
x(4)^2 x(4)*y(4) y(4)^2 x(4) 1;
x(5)^2 x(5)*y(5) y(5)^2 x(5) 1;
x(6)^2 x(6)*y(6) y(6)^2 x(6) 1;
x(7)^2 x(7)*y(7) y(7)^2 x(7) 1;
x(8)^2 x(8)*y(8) y(8)^2 x(8) 1;
x(9)^2 x(9)*y(9) y(9)^2 x(9) 1;
x(10)^2 x(10)*y(10) y(10)^2 x(10) 1 ]
end

댓글 수: 11

Right, this works! This is basically the code that I'm working on. Will it be possible to write matrix A in a single line of code maybe?
if true
%%In this part, we estimate the orbit of the asteroid from the data in
% d.x and d.y
x = d.x;
y = d.y;
% The orbit of an asteroid is given by a conic
% (*) y = c(1)*x.^2 + c(2)*x.*y+c(3)*y.^2+c(4)*x+c(5)
% Find the matrix A and the vector b.
A = sym( x^2 x*y y^2 x 1 ) % FIX THIS!
b = sym('y', [10,1]) % FIX THIS!
% Find the size of the matrix A
size(A)= 10 5
end
Inputing the one that you gave on a new script works great but adding it into this file is bringing up errors. Unexpected MATLAB expression .
Marta Salas
Marta Salas 2014년 3월 13일
Do you have any special interest on working on symbolic? I mean, from your code i deduce you have numeric values for x and y, do you want to use them?
Michelle Ashwini
Michelle Ashwini 2014년 3월 13일
편집: Michelle Ashwini 2014년 3월 13일
No, I don't actually. While reading up, symbolic seemed like the better choice. There are no numerical values for x and y. Its basically a Ac=b matrix where c = [c1 c2 c3 c4 c5], having to solving for c in terms of x and y.
ok. What about this? :
if true
%%In this part, we estimate the orbit of the asteroid from the data in
% d.x and d.y
x = d.x;
y = d.y;
% The orbit of an asteroid is given by a conic
% (*) y = c(1)*x.^2 + c(2)*x.*y+c(3)*y.^2+c(4)*x+c(5)
% Find the matrix A and the vector b.
x = sym('x', [10 1]);
y = sym('y', [10 1]);
A =[x.^2 x.*y y.^2 x 1] % FIX THIS!
b = sym('y', [10,1]) % FIX THIS!
% Find the size of the matrix A
[r,c]=size(A)
end
Michelle Ashwini
Michelle Ashwini 2014년 3월 13일
I understand what you've written. I created a new script with the code you showed and it gave me the following errors.
Just out of curiosity, is there a way of using repmat here instead? I managed to get it to work with numbers but not with the respective variables.
Marta Salas
Marta Salas 2014년 3월 14일
편집: Marta Salas 2014년 3월 14일
A =[x.^2 x.*y y.^2 x ones(10,1)] % FIX THIS!
sorry about that.
repmat is used to replicate the same array several times. In your case it's not the same array, it's a different value of the array.
Michelle Ashwini
Michelle Ashwini 2014년 3월 14일
This is great! Just tried it out and it ran perfectly! Right! Different value of array. That genuinely makes more sense.
Thank u for your time and effort! Appreciate it!
Marta Salas
Marta Salas 2014년 3월 14일
you're welcome :)
Michelle Ashwini
Michelle Ashwini 2014년 3월 14일
Hi, I tried this again on another computer and got the following error Undefined function 'sym' for input arguments of type 'char'. Is there suppose to be any additional materials installed in it in order for the sym function to work? When i type help syms its says sum not found. How do i go about this?
Marta Salas
Marta Salas 2014년 3월 14일
편집: Marta Salas 2014년 3월 14일
Type "ver" on the command line. MATLAB lists all the installed toolboxes. Look for Symbolic Math Toolbox. If you don't have the toolbox, you can not use the symbolic functions.
Michelle Ashwini
Michelle Ashwini 2014년 3월 14일
Right. It does not have the symbolic math toolbox installed. Is there another way to to the same thing?

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 13일
편집: Azzi Abdelmalek 2014년 3월 13일

0 개 추천

out=[x.^2 x.*y y.^2.*x ones(10,1)]
% x and y are column vextors

질문:

2014년 3월 13일

댓글:

2014년 3월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by