parallel computing apply to my problem

조회 수: 13 (최근 30일)
Mallesh
Mallesh 2025년 1월 9일
답변: Walter Roberson 2025년 1월 9일
clc;
clear all;
close all;
tic;
N=10;
a=zeros(1,N+1);
b=zeros(1,N+1);
syms t a b
a(1)=2;b(1)=-3;
for i=1:7
v1=(a(i)*t+5*a(i)*t^2+30*b(i)*t);
v2=(b(i)*t-20*b(i)*t^3+30*a(i)*b(i)*t);
a(i+1)=diff(v1,t);
b(i+1)=diff(v2,t);
end
toc
fplot(v1,[0 0.1],'b');
;;;i want to go for loop till 250 for above kind of problem when there are 8 equations means v1,v2...v8.it is taking so much of time and sometimes matlab is not responding.Please help me how can i wrote that proble with parallel computing or any some other simple programmimg

채택된 답변

Walter Roberson
Walter Roberson 2025년 1월 9일
Change
a(i+1)=diff(v1,t);
b(i+1)=diff(v2,t);
to
a(i+1) = expand(diff(v1,t));
b(i+1) = expand(diff(v2,t));
Although the expand() operation takes some time, it reduces the complexity of the expressions significantly, leading to much much faster diff() in the following steps.

추가 답변 (1개)

Matt J
Matt J 2025년 1월 9일
편집: Matt J 2025년 1월 9일
Skipping the symbolic operations will speed things up,
tic;
t=linspace(0,0.1,1000)';
tsquared=t.^2;
[a,b]=deal(nan(numel(t), 251 ));
a(:,1)=2;b(:,1)=-3;
for i=1:250
ai=a(:,i); bi=b(:,i);
a(:,i+1) = ai.*(1 + 10*t) + 30*bi;
b(:,i+1) = bi.*(1 - 60*tsquared) + 30*ai.*bi;
end
v1=a(:,7);
toc
Elapsed time is 0.059089 seconds.
plot(t,v1,'b');

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by