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 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by