4 views (last 30 days)

I am trying to solve this

omegas=0:1:10;

RR=40:70;

d=90;

for i=1:length(omegas)

for c=1:length(RR)

gg=d+(omegas.*RR);

end

end

for every value of omegas, I want to calculate gg. The idea is that gg should be a 31 by 11 matrix. Means that each omegas is calculated with all values of RR

Guillaume
on 8 Aug 2019

Edited: Guillaume
on 8 Aug 2019

The vectorised version of what you intended with your loop (but didn't achieve):

R=15;

r=5;

epsilon=100;

delta=(R-r)*(epsilon/100);

Theta = 5:10005; %a ROW vector

omega_b1 = (1:9)'; %a COLUMN vector. The two vectors must be along different dimensions

x_b1 = delta*cos(omega_b1) + r*cos(Theta); %automatic expansion of compatible arrays

y_b1 = delta*sin(omega_b1) - r*sin(Theta);

Vb_x1 = -r*Theta.*sin(Theta) - (R - r)*epsilon*omega_b1.*sin(omega_b1)/100;

Vb_y1 = -r*Theta.*cos(Theta) + (R - r)*epsilon*omega_b1.*cos(omega_b1)/100;

ab_x1 = -r*Theta.^2.*cos(Theta) - (R - r)*epsilon*omega_b1.^2.*cos(omega_b1)/100;

ab_y1 = r*Theta.^2.*sin(Theta) - (R - r)*epsilon*omega_b1.^2.*sin(omega_b1)/100;

I've removed a lot of unnecessary brackets.

For how this works, see compatible array sizes

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733045

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733045

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733051

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733051

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733106

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733106

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733110

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733110

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733111

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/475358-group-maths-on-for-loop#comment_733111

Sign in to comment.