Solve for array of values for cos and sin functions returning [0x1 sym]

10 visualizzazioni (ultimi 30 giorni)
Hello,
I am having problems with using an array in a cosine function, I have replicated the problem in a much simpler example code:
clear all
c = 1:1:10;
syms x y
a = x^2 + sind(c) -y == 3;
b = x - cosd(c) +y ==5;
solve([a b], [x y])
ans =
struct with fields:
x: [0×1 sym]
y: [0×1 sym]
I am expecting this to return an array of each iteration of sind(c), or some way of doing so, but instead I just get nothing at all.
I thought I had my head around Matlab but this one has stumped me, also I'm a first time user of Matlab forums so I hope the formatting has come out OK, I googled how and just found posts about how annoying it is explaining to forum newbies to format your code :P
  3 Commenti
Dylan Gannan
Dylan Gannan il 24 Giu 2019
I have edited it, cheers.
My question is how do I solve for each array value so that I can plot its output.
I am plotting the position of a link in a walking robot mechanism for a 360 degree rotation of it's crank. So one of my theta values is going to have 1:1:360. I made that question above to simplify and define my error.

Accedi per commentare.

Risposta accettata

Alex Mcaulley
Alex Mcaulley il 24 Giu 2019
One way:
syms x y c
a = x^2 + c - y == 3; % function a is overwritten in the next line!
a = x^2 + sin(c*pi/180) - y == 3; %c in degrees
b = x - cos(c*pi/180) + y == 5;
res = solve([a b], [x y]);
resx = double(subs(res.x,c,1:1:10));
resy = double(subs(res.y,c,1:1:10));

Più risposte (0)

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by