ronkok / Hurmet

Rich text editor on the web, featuring live calculations.
https://hurmet.org/
25 stars 0 forks source link

UDF with vectors #26

Closed swopnil123 closed 3 months ago

swopnil123 commented 3 months ago

This may not be an appropriate title for this. But can you answer me why we cannot return values from UDF if we put vectors as an argument?

image

ronkok commented 3 months ago

I'll look into it.

Please include the text of your example, so I don't have to retype what I see in an image.

swopnil123 commented 3 months ago

I'll look into it.

Please include the text of your example, so I don't have to retype what I see in an image.

I'm uploading the file here. You can take a look. Thank you! HurmetFile (1).md

ronkok commented 3 months ago

Say that a function contains a condition:

if condition
    V = scalar × vector
else
    V = scalar
end

Hurmet will either multiply the scalar times all of the vector or none of it. Hurmet conditions are not disguised for loops.

If you want a function to apply a condition to each element in a vector, you'll need to write your own for loop. For this example, you'll want a function something like:

function Ch2(T, T_a, T_c, T_d, α)
    C = []
    for el in T
        if el ≤ T_a
            C = C & (1 + (α - 1) × el / T_a)
        elseif T_a ≤ el and el ≤ T_c
            C = C & α
        elseif T_c ≤ el and el ≤ T_d
            C = C & α × T_c/el
        elseif  el ≥ T_d
            C = C & (α × T_c × T_d) / el²
        end
    end
    return C
end

I've just fixed a bug in Hurmet's for loop. You'll get the updated code the next time you navigate to Hurmet.org after being away for four hours.

swopnil123 commented 3 months ago

Thanks! a lot. This helps.

I'm closing this. I'll try to plot these for different scenario and if anything arises then I'll report it as a separate issue.