How to plot an angle (theta) vs Current for the following question

조회 수: 9 (최근 30일)
I am new to Matlab.
I wanted to find the Torque given as T= A*I*cos(theta) - B*I.^2*sin(2*thetha)
with A= 0.01 B= 0.001; I varies from 0 to 100 and thetha from 0 to 45.
I want to find the maximum T (Torque) and plot I vs Theta
This my basic syntax:
A=0.01; %Wb is the unit of A
B=0.001; %H is the unit of Inductance
I=(0:10:100);
theta=(0:1:45);
T=A*I.Cos(theta)-B*I.^2*Sin(2*theta);

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 19일
A=0.01; %Wb is the unit of A
B=0.001; %H is the unit of Inductance
I =(0:10:100); %row!
theta=(0:1:45).'; %column!
T = A .* I .* cosd(theta) - B .* I.^2 .* sind(2*theta);
surf(I, theta, T)
xlabel('I'); ylabel('theta'); zlabel('Torque')
[maxT, idx] = max(T(:));
[r,c] = ind2sub(size(T), idx);
best_theta = theta(r);
best_I = I(c);
fprintf('best torque is %g at theta = %g and I = %g\n', maxT, best_theta, best_I);
best torque is 1 at theta = 0 and I = 100
  댓글 수: 7
Varun Nair
Varun Nair 2021년 7월 20일
You mean to say using meshgrid?
Walter Roberson
Walter Roberson 2021년 7월 20일
Yes, using meshgrid. You can avoid using ind2sub() -- but you still end up using linear indexing.
A=0.01; %Wb is the unit of A
B=0.001; %H is the unit of Inductance
I_vec =(0:10:100);
theta_vec = (0:1:45);
[I, theta] = meshgrid(I_vec, theta_vec);
T = A .* I .* cosd(theta) - B .* I.^2 .* sind(2*theta);
surf(I, theta, T)
xlabel('I'); ylabel('theta'); zlabel('Torque')
[maxT, idx] = max(T(:));
best_theta = theta(idx);
best_I = I(idx);
fprintf('best torque is %g at theta = %g and I = %g\n', maxT, best_theta, best_I);
best torque is 1 at theta = 0 and I = 100

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by