Unable to sove for all parameters

조회 수: 1 (최근 30일)
Chitransh Singh
Chitransh Singh 2019년 4월 16일
댓글: Torsten 2019년 4월 16일
i have an equation with a number of variables and i need to calculate the velocity. the equation is-
v=[((ta*xp)+(tb*xn))*(w/(2*pi))]
where ta, xp, tb, xn and w all vary within a certain limit. I cannot do matrix calculation due to unequal matrix dimensions.. I am applying the for loop to get the results forr each value of each parameter. But what i am getting in the workspace is a 1*1 matrix.
The code i am using is-
clc
clear all
for ta=linspace(0.017,0.349,20)
for xp=linspace(0,20,20)
for tb=linspace(0.017,0.349,20)
for xn=linspace(0,20,20)
for w=linspace(1.67,18.33,11)
v=[((ta*xp)+(tb*xn))*(w/(2*pi))]
end
end
end
end
end
Plz help me to solve this equation to get different values of v for each value of all the variables. Also help me on how to plot a graph with w on x axis and rest all parameters on y-axis from the solution of this equation
I guess i need to get 20*20*20*20*11=1760000 values for this equation.

답변 (1개)

Kevin Chng
Kevin Chng 2019년 4월 16일
clc
clear all
i=1;
summary=table;
for ta=linspace(0.017,0.349,20)
for xp=linspace(0,20,20)
for tb=linspace(0.017,0.349,20)
for xn=linspace(0,20,20)
for w=linspace(1.67,18.33,11)
summary.w(i)=w;
summary.v(i)=[((ta*xp)+(tb*xn))*(w/(2*pi))];
summary.ta(i)=ta;
summary.xp(i)=xp;
summary.tb(i)=tb;
summary.xn(i)=xn;
i=i+1
end
end
end
end
end
plot(summary.w,summary.v,'ro')
hold on
plot(summary.w,summary.ta,'bo')
plot(summary.w,summary.xp,'go')
plot(summary.w,summary.tb,'co')
plot(summary.w,summary.xn,'yo')
legend('v','ta','xp','tb','xn')
Now your 1x1760000 double data is save in v. Plot them with 0 marker.
  댓글 수: 1
Torsten
Torsten 2019년 4월 16일
Or use "ndgrid":
https://de.mathworks.com/help/matlab/ref/ndgrid.html

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by