Gincliijj =
how to simplify/solve a trigonometric function
Show older comments
I have this function, it is a solar radiation per second (ii) over a year (jj) and it is taking the most time to be solved:
Gincl(ii,jj)=G(ii,jj).*cosd(angle)+1000*(-sind(a(jj)).*cosd(lat)*sind(angle).*cosd(0)+cosd(a(jj)).*sind(lat).*cosd(0).*sind(angle).*cosd(H(ii))+cosd(a(jj)).*sind(0).*sind(angle).*sind(H(ii)));
is there any way to solve this equation in matlab, so it takes less time? I am not using any build in block (don't know how) and it is written as it is in the .m file. thanks.
1 Comment
Steven Lord
on 23 Aug 2026 at 2:39
When you say "solve this equation", what do you know and what are you trying to find? Are you looking for the value of the variable angle (which you might want to rename, since there's already an angle function in MATLAB) and you know the values of each of the other angles? Are you trying to compute Gincl knowing all the other variables?
What sizes are the known variables?
How long does your code take now and what is your requirement for the maximum amount of time you want it to take?
I'm assuming you're doing some looping (probably a double loop, one over ii and one over jj) -- consider vectorizing and/or precomputing cosd(angle), sind(a), cosd(lat), sind(angle), cosd(a), and sind(lat) outside your loops and simply indexing into those precomputed results inside the loop or using them directly. This avoids having to repeatedly call the trig functions.
I know the original poster asked this over a decade ago, but for others who are in similar situations and find this post in the future these are all good questions to ask yourself or approaches to try.
Answers (2)
Georgios
on 22 Aug 2026 at 21:12
0 votes
make a function like: function y = Gincle(ii,jj,lat,angle)
and then y = the equation
end
syms ajj Giijj Hii real
syms angle lat real
Gincliijj = Giijj.*cosd(angle)+1000*(-sind(ajj).*cosd(lat)*sind(angle).*cosd(0)+cosd(ajj).*sind(lat).*cosd(0).*sind(angle).*cosd(Hii)+cosd(ajj).*sind(0).*sind(angle).*sind(Hii))
simplify(Gincliijj)
simplify(Gincliijj, 'steps', 10000)
As simplify even to 10000 steps does not produce any improvement, we can conclude that there is probably no available speed improvement, other than not explicitly calculating the cosd(0) and sind(0) terms -- and since sind(0) is 0, dropping calculation of the rest of the appropriate addend.
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!