How I can extend this function

6 次查看(过去 30 天)
Marius Dranca
Marius Dranca 2013-4-5
I made this funcion to get any value of L between theta=-22.5:22.5 deg and I=0:6 .
%Inductance versus teta and current
function [L] = Induc(teta,current)
L0 = [0.076 0.077 0.079 0.098 0.128 0.137 0.128 0.098 0.079 0.077 0.076];
L1 = [0.076 0.077 0.079 0.098 0.128 0.137 0.128 0.098 0.079 0.077 0.076];
L2 = [0.076 0.077 0.079 0.098 0.122 0.134 0.122 0.098 0.079 0.077 0.076];
L3 = [0.068 0.069 0.071 0.086 0.103 0.108 0.103 0.086 0.071 0.069 0.068];
L4 = [0.060 0.061 0.063 0.075 0.086 0.090 0.086 0.075 0.063 0.061 0.060];
L5 = [0.054 0.055 0.057 0.065 0.074 0.078 0.074 0.065 0.057 0.055 0.054];
L6 = [0.050 0.051 0.052 0.059 0.065 0.069 0.065 0.059 0.052 0.051 0.050];
T = [-22.5 -18 -13.5 -9 -4.5 0 4.5 9 13.5 18 22.5];
I = 1:1:6;
Lx = [L0;L1;L2;L3;L4;L5;L6];
L = interp2(T,I,Lx ,teta,current,'cubic');
end
How I can extend it to obtain more values of L, for exemple between -360 and 360 deg. and for I between -6 and 0. I mention that the values of L are the same for theta in the interval [22.5;67.5],for [67.5;112.5] and so on.(they are corelate, for ex for theta=0, L will be the same in theta=45; the same for theta=1 and theta=46 ) Thanks!
  1 个评论
Jan
Jan 2013-4-5
There is no "theta" in your code, so how can we know, what you want to achieve? Please formulate the question again with more details.

请先登录,再进行评论。

回答(1 个)

Ahmed A. Selman
Ahmed A. Selman 2013-4-5
The function you wrote above has an error at
I = 1:1:6;
it should be
I = 0:1:6;
% or simply
I = 0:6;
Since you are interested with interpolation, I'm not sure how to explain (obtain more values of L), does it mean extend the range of L (with fixed number of points) or extend the number of points of L (fixed range of L), or both. However, here are few things to try:
1) Try the following method to extend number of points, and the output range:
% The same function but have its output over input range Theta and I
for Theta=-360:360
i=Theta+361;
for I=-6:0
j=I+7;
L(i,j)=Induc(Theta,I);
end
end
but it will give you NaN output (inconsistent with L0,L1,L2..etc).
2) Try re-writing your Induc.m function as Induc2.m function, as in:
function [L] = Induc2(theta,current,I,T)
L0 = [0.076 0.077 0.079 0.098 0.128 0.137 0.128 0.098 0.079 0.077 0.076];
L1 = [0.076 0.077 0.079 0.098 0.128 0.137 0.128 0.098 0.079 0.077 0.076];
L2 = [0.076 0.077 0.079 0.098 0.122 0.134 0.122 0.098 0.079 0.077 0.076];
L3 = [0.068 0.069 0.071 0.086 0.103 0.108 0.103 0.086 0.071 0.069 0.068];
L4 = [0.060 0.061 0.063 0.075 0.086 0.090 0.086 0.075 0.063 0.061 0.060];
L5 = [0.054 0.055 0.057 0.065 0.074 0.078 0.074 0.065 0.057 0.055 0.054];
L6 = [0.050 0.051 0.052 0.059 0.065 0.069 0.065 0.059 0.052 0.051 0.050];
% T = [-22.5 -18 -13.5 -9 -4.5 0 4.5 9 13.5 18 22.5];
% I = 0:1:6;
Lx = [L0;L1;L2;L3;L4;L5;L6];
L = interp2(T,I,Lx ,theta,current,'cubic');
end
Here we used (I and T) as input arguments. The are predefined before using the function. To ensure that (I and T) have the same dim as L0,L1.. etc. type this in the command window:
I=-6:0;
T=linspace(-360,360,11);
[L] = Induc2(theta,current,I,T)
and your original function works as:
I=0:6;
T=linspace(-22.5,22.5,11);
[L] = Induc2(theta,current,I,T)
Tips: You can also use
T = -22.5:4.5:22.5;
OR
T = linspace(-22.5,22.5,11);
instead of
T = [-22.5 -18 -13.5 -9 -4.5 0 4.5 9 13.5 18 22.5];
Tip #2: If you want I=-6:6 and T=-360:360; use the same methods above, but be sure to input values of L0,L1,..etc., with similar sizes.

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by