Values not populating in table for variable
Afficher commentaires plus anciens
I have the following code:
clc
clear all
close all
%define some initial variables
theta = pi/4;
R = 0.0006;
w = 1.318*R;
format longg
%calculate the vector length, p, to the edge of the ellipse
phi=0:0.01:2*pi;
p = (w*sin(theta)^2*cos(phi)+sqrt(R^2*sin(phi).^2+R^2*sin(theta)^2*cos(phi).^2-w^2*sin(theta)^2*sin(phi).^2))/(sin(phi).^2+sin(theta)^2*cos(phi).^2);
x = p.*cos(phi);
y = p.*sin(phi);
When I run this and look at the results in Workspace, the tables holding the values of x and y each have 629 columns with values. However, the table holding the values of p only has one column with one value.
It looks like Matlab is populating the x and y table using only the one value of p and then multiplying it by looping phi to yield the 629 entries. What I need is for Matlab to change "p" with each value of phi and then calculate the corresponding values of x and y. How do I get Matlab to calculate all of the values of p based on the preceding line of code which is:
phi=0:0.01:2*pi;
Réponses (1)
%clc
%clear all
%close all
%define some initial variables
theta = pi/4;
R = 0.0006;
w = 1.318*R;
format longg
%calculate the vector length, p, to the edge of the ellipse
phi=0:0.01:2*pi;
There's a element-wise dot symbol missing between the numerator and denominator division sign/operator (scroll to right) -
% v
p = (w*sin(theta)^2*cos(phi)+sqrt(R^2*sin(phi).^2+R^2*sin(theta)^2*cos(phi).^2-w^2*sin(theta)^2*sin(phi).^2))./(sin(phi).^2+sin(theta)^2*cos(phi).^2);
x = p.*cos(phi);
y = p.*sin(phi);
whos
Now as you can see, p (along with x and y) is also same size as phi (1x629).
1 commentaire
Robert Demyanovich
le 16 Oct 2025
Catégories
En savoir plus sur Calculus dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!