Alternative to ctrl-c -> ctrl-v three thousand times

Hi, I'm looking to build a basic simulator for an electric car running along a defined circuit with three corners and three straights. I've calculated the corner speed to provide an initial speed into a straight, however i'm having issues getting the acceleration from that point
Essentially the simulator uses the initial velocity to determine wheel speed and thus rpm, this then determines motor torque via a data set thus giving acceleration. The acceleration is then used to determine a new velocity over a step length of 0.5m whilst outputting a step time
Essentially each new velocity at the end of a 0.5m step is used to determine another velocity for the next 0.5m step, whilst allowing for the cumulative times to be taken
The problem is that the individual straight is 500m long thus manually inputting each step would require 1000 individual steps (plus another 2600 for the other straights and a few thousand for the braking deceleration), i'm sure there is a better way but not quite sure where to start
I've not used Matlab before and would usually use Excel, but I feel that Matlab should be a better tool for this kind of thing
Any help appreciated
Thanks
{T1v=sqrt((MUc*T1r*(m*g))/(m-MUc*T1r*CLA)); %First corner velocity in m/s
T2v=sqrt((MUc*T2r*(m*g))/(m-MUc*T2r*CLA)); %Second corner velocity in m/s
T3v=sqrt((MUc*T3r*(m*g))/(m-MUc*T3r*CLA)); %Third corner velocity in m/s
T1t=((pi*(2*T1r))/(360/T1theta))/T1v; %First corner time in seconds
T2t=((pi*(2*T2r))/(360/T2theta))/T2v; %Second corner time in seconds
T3t=((pi*(2*T3r))/(360/T3theta))/T3v; %Third corner time in seconds
xrpm=[0,1000,2000,3000,4000,4750,5000,6000,7000,8000];
ytorque=[321.66,321.66,321.66,321.66,321.66,321.66,305.58,254.65,218.27,190.99];
ypower=[0,33.7,67.4,101.1,134.7,160,160,160,160,160];
figure
plot(xrpm,ytorque) %Torque vs rpm for motor
figure
plot(xrpm,ypower) %Power vs rpm for motor
rpmS1_0=((T1v/(pi*(2*r)))*60)*FinalDrive*GearR; %vehicle speed converted to motor rpm
ytorqueS1_0=interp1(xrpm,ytorque,rpmS1_0); %Motor rpm used to derive torque via graph
TracS1_0=((ytorqueS1_0*FinalDrive*GearR)/r)*nGears; %Tractive Effort
AccelS1_0=((TracS1_0-(CDA*T1v^2)-RR)/(m*g))*g; %Acceleration out of T1
TimeS1_0=(-T1v+sqrt(T1v^2+2*AccelS1_0*(S1-S0)))/(AccelS1_0); %Time taken to cover step
VS1_1=T1v+AccelS1_0*TimeS1_0; %Velocity at end of step
rpmS1_1=((VS1_1/(pi*(2*r)))*60)*FinalDrive*GearR;
ytorqueS1_1=interp1(xrpm,ytorque,rpmS1_1) ;
TracS1_1=((ytorqueS1_1*FinalDrive*GearR)/r)*nGears ;
AccelS1_1=((TracS1_1-(CDA*VS1_1^2)-RR)/(m*g))*g;
TimeS1_1=(-VS1_1+sqrt(VS1_1^2+2*AccelS1_1*(S1-S0)))/(AccelS1_1);
VS1_2=VS1_1+AccelS1_1*TimeS1_1;}

回答 (1 件)

Stephen23
Stephen23 2018 年 4 月 25 日
移動済み: Steve Miller 2023 年 4 月 23 日

0 投票

@OhGodMatlab: judging by your username you need to take a short break and drink a nice coffee. The first thing to remember is that MATLAB is not Excel, and you will have to learn different ways of thinking and problem solving.

In excel formulas are copied everywhere: filled down columns or along rows to work with the data. However in the real world of programming, copy-and-pasting code is sign that you are doing it very wrong. Computers are really only good at doing one thing: repeating simple operations in a loop, so when you find yourself dopy-and-pasting code and making small changes, then you are just doing the computer's job for it (as well as tediously creating code that is complex and hard to maintain).

You need to put all of your data into vectors/matrices/arrays. Use loops or vectorized code as required. Experiment, read the documentation, practice. Use the resources available to you: you are not the first person to simulate a process which changes at fixed points, so find some similar examples and see how they did it. Read this:

https://www.mathworks.com/matlabcentral/answers/228557-experts-of-matlab-how-did-you-learn-any-advice-for-beginner-intermediate-users

Do the introductory tutorials (yes, really), which will show you basic concepts that you need to know:

https://www.mathworks.com/help/matlab/getting-started-with-matlab.html

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2018 年 4 月 25 日

移動済み:

2023 年 4 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by