Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8242607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:13:35+00:00 2026-06-07T21:13:35+00:00

Hi I am working with the following code (Brute force method). PV_supply and WT_supply

  • 0

Hi I am working with the following code (Brute force method).
“PV_supply” and “WT_supply” and “Demand” are 48×1 size.
what I am trying to do is calculate the “Energy_battery” value for each of the 48 rows. However to do this I need to use the value of “Energy_battery” from the previous row in the calculations of each row which I haven’t figured out how to code and was hoping for some help on this. therefore the equation for “Energy_battery” in row 1 uses the “Energy_battery” value in row 1 for the equation etc

My code is:

for number_panels = 0:5

for number_turbines = 0:3


    for h=1:24 %# hours

        for d = 1:number_of_days %# which day

            n = h + 24*(d-1);

 Energy_battery(number_panels + 1, number_turbines + 1,1,1) = 100;

Energy_battery(number_panels + 1, number_turbines + 1,n+1,1) =...
Energy_battery(number_panels + 1, number_turbines + 1,h,1)  + ...
((PV_supply(n)*number_panels + WT_supply(n)*number_turbines) - ...   
Demand(n)/inverter_efficiency)*battery_charging_efficiency;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:13:37+00:00Added an answer on June 7, 2026 at 9:13 pm

    This is an extended comment, only an answer to parts of your question, though I think it has relevance to your other recent questions too.

    It’s helpful to think of Matlab as an array processing language, the natural ‘unit’ of computation is an array rather than a scalar as in many other languages. If you find yourself writing loops to iterate over the elements of an array stop and think, there is likely to be a more ‘natural’ way of expressing the same calculation without the loops. There’s nothing absolutely wrong with loops but over-reliance on them can have 2 deleterious effects:

    1. Matlab code without loops is often (much) faster than the equivalent with loops;
    2. Code with loops is often more cluttered, and requires more variables to be used, than the equivalent without loops. The clutter is a hindrance when it comes to understanding the code

    So, for example, your statement

    Energy_battery(number_panels + 1, number_turbines + 1,1,1) = 100;
    

    could be lifted out of your loop nest entirely and rewritten as

    Energy_battery(:,:,1,1) = 100;
    

    Now, for the main bulk of your code, if I’ve understood it correctly, you want to update each element at Energy_battery(:,:,n+1,1) based on the values in Energy_battery(:,:,n,1) and in element n of the other vectors you have. First, let’s tidy this up

    ((PV_supply(n)*number_panels + WT_supply(n)*number_turbines) - Demand(n)/inverter_efficiency)*battery_charging_efficiency
    

    could be rewritten as

    ((PV_supply*number_panels + WT_supply*number_turbines) - Demand/inverter_efficiency)*battery_charging_efficiency
    

    for Matlab multiplying an array by a scalar applies the multiplication to each element of the array. And again, this doesn’t need a loop over the values of an index such as n.

    I’m afraid I have to go and do some work now, will come back later and finish the lesson if no-one else does. Feel free to edit this answer if you want to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get the following code working. It's a progress bar
I'm trying to get the following code working: string url = String.Format(@SOMEURL); string user
I'm trying to get a UIWebView working with the following code: NSString *urlAddress =
Hi I am working with the brute force method to examine possible combinations of
I'm working on the following code that is trying to connect to DB, but
In the following (working) code example, the templated register_enum() function is used to iterate
I am working on the following code: import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import
Right now I have the following code working: @UiHandler(usernameTextBox) void onUsernameTextBoxKeyPress(KeyPressEvent event) { keyPress(event);
We have the following code working for a complex rails form with checkboxes. I'm
The following code is working great in a normal console application: private void button1_Click(object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.