Values not populating in table for variable
조회 수: 15 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Dyuman Joshi
2025년 10월 16일
%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).
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!