Values not populating in table for variable
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Robert Demyanovich
am 16 Okt. 2025 um 17:12
Bearbeitet: Walter Roberson
am 16 Okt. 2025 um 19:16
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;
0 Kommentare
Antworten (1)
Dyuman Joshi
am 16 Okt. 2025 um 17:24
%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).
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!